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
May 31, 2021

I try the citrus.jsx script in Photoshop CC 2021 and get error 21 when I press the F1 key in a mac.

Then I get several erro 24 dialogs when I press F1 ket for one sec and then switch to F2 key.

What do these errors mean?

 

 

Inspiring
June 5, 2021

Loll, you don't read my answers, I told you twice you can combine code with BridgeTalk. Then you don't have to hold a key for a second, but 200 times less, that is enough time to release main key and press other key within this time. When you keep your second finger over F1, and next one on F2 and F3, it's not any trick to use them smootly:

 

if ($.engineName)
	((bt = new BridgeTalk()).target = BridgeTalk.appSpecifier,
	(bt.body = '$.evalFile(' + $.fileName.toSource() + ')', bt.send()))
else{
	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]]()
}

 


The BridgeTalk code work in mac but not smoothly. The function key needs to be held down for a few milliseconds before the alert pops up. The last code snippet works better because there is no delay. Press the function key and the alert pops up immediately.