Skip to main content
M.Hasanin
Inspiring
October 3, 2022
Answered

can i connect keystrokes directly to functions?

  • October 3, 2022
  • 1 reply
  • 324 views

Hi Experts, i wonder if i can connect keystrokes directly to functions instead of double click or (run) the script everytime with UI , i mean can i run script once and call the functions via keystrokes instead of showing Script UI that need to be Active to respond? and thanks in advance

#targetengine "mysession";
var w = new Window("palette", {independent:true});
w.orientation = "stack"
w.alignment = "center"

var edit = w.add ("edittext")
edit.visible = false
edit.active = true;

w.text = "Send KeyStrokes to Execute Functions"
w.preferredSize.width = 200;
w.alignChildren = ["left", "top"]; 
w.orientation = "row"; 
w.spacing = 5;
w.margins = 16
w.add ("statictext", undefined,"Send KeyStrokes to Execute Functions");

w.show();

w.addEventListener ("keydown", function keyPressed(key){
    switch (key.keyName) {
        case "U":
        PressU();
        case "V":
        PressV();
        case "H":
        PressH();
        case "M":
        PressM();
        case "Escape":
        w.close()
    }
})

 

This topic has been closed for replies.
Correct answer Peter Kahrel

If I understand you correctly, no, you can't. It looks as if you're simply trying to program your own keyboard shortcut handler. There's no need, InDesign has one. Store your functions as individual scripts and assign shortcut keys to them in InDesign's keyboard shortcuts editor.

1 reply

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
October 3, 2022

If I understand you correctly, no, you can't. It looks as if you're simply trying to program your own keyboard shortcut handler. There's no need, InDesign has one. Store your functions as individual scripts and assign shortcut keys to them in InDesign's keyboard shortcuts editor.

M.Hasanin
M.HasaninAuthor
Inspiring
October 3, 2022

@Peter Kahrel Thanks a lot, maybe this feature will be added in the future!

Mohammad Hasanin