Skip to main content
Inspiring
August 7, 2022
Question

Action or javascript; how to program "escape key"

  • August 7, 2022
  • 4 replies
  • 3757 views

Hi,

I am looking for to way to add an Action event or javascript to program an "escape key" event.

 

I need to exit Ps edit boxes (opacity, flow, etc...) and/or exit Free Transform before the rest of my Action/Javacript executes.

 

Manually pressing the ESC key (Mac) does exactly what I want, but I would like to do this programmatically as part of an action or javascript.

...TIA for looking

This topic has been closed for replies.

4 replies

Stephen Marsh
Community Expert
August 7, 2022

@contactzero  Perhaps a .confirm() and conditional script step could offer the choice of running the free transform or to play the canvas action instead? This way you avoid the issue of having the transform already set and then needing to escape it.

Zesty_wanderlust15A7
Known Participant
August 7, 2022

From a "big name" scripter, I have the quote, "It’s not possible to send keys with a PS script."

I think I do understand the problem, as I try a lot of this cool stuff myself.

I use an external helper for some of this (for PC that would be a small AutoIt.exe that's running in the background, although sometimes I open another one from within an action.).

I will give one example that might help you. Let's say you have F1 programmed as your Run/Continue key for actions (that's what I do). Now, in your helper app you could catch the F1 key and do something else first, like ESC.

To put it very simply, F1 would call this function...

 

Func F1_was_Pressed()								; 	 
 If WinActive("[CLASS:Photoshop]") Then
    Send("{ESC}")										 				 
    Sleep(300)
    Send("{F1}")
  EndIf
EndFunc

 

This can of course cancel out things when you don't want it to..., so further thought or intelligence could be needed. Probably not handy on a key you use all the time, like Run/Continue, but on a key that saves your document, for example (to make sure you have left all fields and the key actually engages).

 

To have someone clicking on an action would be different though... If these actions are always in the same spot, maybe you could have the helper app go to a function depending on where you clicked on the screen. It could possibly intercept the click, do ESC first, then send the real click that runs the action underneath. I'm 99% sure this is possible with this kind of software, and I'm probably doing it somewhere.

For some UI elements, you can detect and decide based on the internal code for that element. This makes it possible to deselect a field, do something, then make that field active again, for example.

In my Mac days 25 years ago, I used QuicKeys. I don't know what's the best one at the moment...

Update:
I just checked if AutoIt can pick up an individual ID or text for each action button, and seems it can't — just cursor coordinates and the color underneath (meaning, your critical actions would have to be in a ±exact spot for the coordinates method to work).

willcampbell7
Brainiac
August 7, 2022

I can't think of a way to catch the ESC key in an Action, but in ExtendScript (JavaScript) you can...

if (ScriptUI.environment.keyboardState.keyName == "Escape") {
    // ESC key has been pressed
}

 

William Campbell
Inspiring
August 7, 2022

I'll look into this... I'm not trying to TRAP the escape, I'm trying to programmatically make the kepress escape - in Photoshop. And I understand this is a security issue and that's why this is difficult.

 

The fault lies within PS for not having a menu command "deselect" method for Free Transform... -- Other than the ESC escape key.

willcampbell7
Brainiac
August 7, 2022

OK pressing the key, not detecting if it's pressed. That's different. I haven't tested this, and I'm not positive of all the values, but this should point you in the right direction. See the Creative Cloud JavaScript Tools Guide page 152 for more about this. https://download.macromedia.com/pub/developer/aftereffects/scripting/JavaScript-Tools-Guide-CC.pdf

initKeyboardEvent() eventObj.initKeyboardEvent (eventName, bubble, isCancelable, view, keyID, keyLocation, modifiersList)  

I'll guess the eventName is either "keydown" or "keyup". keyID is probably "Escape" like the other code. Just guessing though. Do some experients and see what you can learn.

 

William Campbell
c.pfaffenbichler
Community Expert
August 7, 2022

Only the Free Transform seems of interest to me and I am not sure I understand the issue. 

Do you want to allow for user interaction? 

If so the user pressing enter to confirm the transformation seems perfectly reasonable and that can be done when executing the AM-code of the operation with »DialogModes.ALL«. 

 

Maybe you should explain what you are actually trying to achieve and post screenshots to illustrate. 

Inspiring
August 7, 2022

1. I print a lot and resize the canvas a lot. My action finishes with Free Transform, ready for me to resize the layer. If I want to run another action to resize the canvas, I must manually hit excape first. If I don't escape Free Trasform active, my actions won't run, I get a beep. Note: I am in Actions; Button mode.

; I would like to Escape (exit Transform). Escape otherwise is benign or has no ill effects. Alternatively I would like to Reset Transform as long as it exits also.

 

2. Having clicked in an edit box such as; opacity, flow etc. I just don't want unpected values when I execute an action/javascript to set the brush size. Pressing escape key assures that. But I would like program that -- call me a control freak. 🙂   

c.pfaffenbichler
Community Expert
August 7, 2022

Sorry, I may still not understand the issue. 

 

Presumably you enabled user input for the transformation by clicking the »Toggle dialog on/off«-button in the Actions Panel. 

So user input would be necessary by your own choice, whether it is manual transformation and hitting enter (or double-clicking …) or hitting esc. 

 

That an Action cannot be run if another Action is still running seems to be as expected to me. 

 

Maybe a more meaningful process would be viable via Scripting, though I am not sure what the whole process is supposed to encompass.