Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Typically one creates a ScriptMenuAction and then assigns a keyboard shortcut to it in Edit > Keyboard Shortcuts.
Copy link to clipboard
Copied
does this work on both platforms? and would it look like this app.menuActions.item.keyboardShortcuts("option,h");
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Ok that makes sense. Its only listening to the UI event.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more