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]]()

 

Legend
May 30, 2021

It seems to me that there should be an endless loop. Not?

 

Also swears at the line:

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

undefined is not an object

upd.

keyName == undefined

 

upd2.

It seems I misunderstood what the script does. Not a reliable method. And, if you remember, you can assign any number of hotkeys to the script, then everything is easier, but there can also be problems.
Kukurykus
Legend
May 30, 2021

Basicly save script to Presets / Scripts, relaunch Photoshop and assign F1 to appropriate item from File / Scripts. Then press F1 (for one second, that's the time of refresh()) so the script is going to call pomelos function. If you press F1 and then switch your finger to F2 or F3 for the time of lasting second it is going to call lemons or oranges.

 

I used it for some project and never had endless loop, and can't say why it could be unreliable if it always worked for me. To avoid one second of waiting after pressing the function key, you can combine it with BridgeTalk.