Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Trigger an event with key command?

Engaged ,
Jan 17, 2012 Jan 17, 2012

In InDesign CS3_Scripting Guide quote "The following table lists events to which eventListeners can respond. These events can be triggered by any available means, including menu selections, keyboard shortcuts, or script actions." I currently have a script that activates a UI when the user presses save. I am interested in changing that action to happen when a user presses a key.

I do not see any documentation on this. The UI popping up on save all the time is kind of annoying. I was thinking maybe option or command H or anything really.

listen();

function listen(){

var mySampleScriptMenu = app.menuActions.item("$ID/kSave");

var myEventListener = mySampleScriptMenu.eventListeners.add("beforeInvoke", myFunction, false);

}

I am using CS5 mac.

TOPICS
Scripting
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 17, 2012 Jan 17, 2012

Typically one creates a  ScriptMenuAction and then assigns a keyboard shortcut to it in Edit > Keyboard Shortcuts.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 17, 2012 Jan 17, 2012

does this work on both platforms? and would it look like this          app.menuActions.item.keyboardShortcuts("option,h");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 17, 2012 Jan 17, 2012

Yes it does and not it would not.

There's no scripting interface to add keyboard shortcuts, the user has to do that, or a plugin can do it.

Unfortunately.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 18, 2012 Jan 18, 2012

Ok. Instead of creating an event listener I just used  Edit > Keyboard Shortcuts. and set a key command to my script. It was just that easy. I feel kinda stupid on this one. Thank you for teaching.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 01, 2012 Feb 01, 2012

I found this in the Script UI 1-9 PDF.

Listening to the keyboard

To listen to the keyboard, define an event listener using the keyboard event

keydown. Here is an example that prints some properties of the keyboard event

(this doesn't work properly when you target the ESTK):

var w = new Window ("dialog");

var edit = w.add ("edittext");

edit.active = true;

edit.characters = 30;

w.addEventListener ("keydown", function (kd) {pressed (kd)});

function pressed (k)

{

$.writeln (k.keyName);

$.writeln (k.keyIdentifier);

$.writeln (k.shiftKey ? "Shift pressed" : "Shift not pressed");

$.writeln (k.altKey ? "Alt pressed" : "Alt not pressed");

$.writeln (k.ctrlKey ? "Ctrl pressed" : "Ctrl not pressed");

}

w.show ();

I think this is something I might try. I am currently using key board shortcuts in Indesign now but if I write this into the code I will not have to set up on each machine and each version of indd. I am currently using option T to get my script going.

Can you tell me what the d stands for in this function?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 01, 2012 Feb 01, 2012

To listen to the keyboard, define an event listener using the keyboard event

keydown. Here is an example that prints some properties of the keyboard event

(this doesn't work properly when you target the ESTK):

var w = new Window ("dialog");

I believe this only works when the created window has the active focus.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 01, 2012 Feb 01, 2012
LATEST

Ok that makes sense. Its only listening to the UI event.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines