Skip to main content
Inspiring
May 30, 2021
Answered

Keyboard shortcut to execute specific function from script

  • May 30, 2021
  • 1 reply
  • 10825 views

I work with custom Photoshop scripts and keyboard shortcuts.

Is it possible to have a keyboard shortcut execute a specific function within a script?

and, another keyboard shortcut executes another function in the same script?

 

For example?

Citrus.jsx

  • function pomelos(){}
  • function lemons(){}
  • function oranges(){}

 

Keyboard F1 executes the function Pomelos

Keyboard F2 executes the function Lemons

Keyboard F3 executes the function Oranges

 

 

 

This topic has been closed for replies.
Correct answer r-bin

Got it, I realized it is possible to add more than one keyboard shortcut per script in Photoshop.

Each function key alerts the function key number followed by Error 21.

 

The Adobe UXP is the new Unified Extensibility Platform to build panels.

To make it user-friendly the button panel should stay docked to make it accessible.


[Profanity removed]

Remove the first test alert() and refresh() from the script.

1 reply

Kukurykus
Legend
May 30, 2021

Assiang F1 key to the script, basicly for pomelos function. When you want to trigger lemons then during refreshment change your finger from F1 key to F2. Similary if you want to initiate oranges, switch to F3.

 

refresh()

function pomelos() {alert(callee.name)}
function lemons() {alert(callee.name)}
function oranges() {alert(callee.name)}

({1: pomelos, 2: lemons, 3: oranges})[ScriptUI.environment.keyboardState.keyName[1]]()

 

Inspiring
January 9, 2022

Hi, can you please help figuerout how to modify the script to use a a different set of keyobrd keys.

Is it possible for example to use this type of keybord squence? 

F3+command for pomelos function

F6+command+opton for lemons function

F7+command+option+shift for oranges function

Inspiring
January 10, 2022

Assign script to F3, then within second switch to appropriate combination, or hold instead:

 

refresh()

function pomelos() {kS.ctrlKey && alert(callee.name)}
function lemons() {kS.ctrlKey && kS.altKey && alert(callee.name)}
function oranges() {kS.ctrlKey && kS.altKey && kS.shiftKey && alert(callee.name)}

(kN = (kS = ScriptUI.environment.keyboardState).keyName) &&
/[367]/.test(_ = kN[1]) && ({3: pomelos, 6: lemons, 7: oranges})[_]()

 


Thank you, I was not able to make it work. I don't have an idea why the first solution for the f1, f2 and f3 keys works and hte solution for the combiantion keys does not work. I did notice the pomelos function triggers with the F3 function key instead of the F3+command.