Skip to main content
Adirai Maji
Inspiring
April 9, 2020
Question

How to simulate a key-press in ExtendScript?

  • April 9, 2020
  • 3 replies
  • 5696 views

I've been searching for answer to this question like months. The only positive answer I can get is from this thread link in below. Someone answered InitKeyboardEvent() would help. But I can't find a single example to use this function on JavaScript Tool Guide Page 152. Can anyone please tell me if it possible to simulate keypress in extendscript?

 

Link : Stackoverflow Thread 

This topic has been closed for replies.

3 replies

May 5, 2020

I don't think it is possible just from the scripting side. You can however make a simple AE C++ extension that contains a function to send definable keystrokes to an application/window using standard OS functionality, and then call this function directly from the script.

Alan_AEDScripts
Inspiring
May 5, 2020

search the tools guide for .notify()

 

...simulates keypress or UI element click. 

Participant
September 8, 2020

Hi Alan, 

Thanks for your reply above, I too am trying to simulate a key being pressed in Photoshop. Specifically I want to run a command as if the user had pressed the escape key when my panel opens in order to dismiss the start screen.

 

I tried looking at the Javascript Tools Guidefor .notify() as you mentioned but still don't quite understand how to use it in a .jsx file being run. Could you possible give an example please?

 

Extremely grateful for any help you could provide,

Thanks, Ben

pravb93889753
Participant
April 26, 2020

Did you got it to work? I am also looking into similar issue.

Adirai Maji
Inspiring
April 26, 2020

Still looking for answer... This question on my mind like 1 months.. No solution yet... I can't able to comment on the thread I just shared.If it possible for you please ask an example for it over there and share the solution if you got any...

schroef
Inspiring
January 16, 2021

For what system are you looking for actually, that kind of a big deal. Im also looking for this and then especially Windows, i already know the OSX version of this. Below is the OSX version which presses the right arrow key

 

app.system( 'osascript -e \'tell application "System Events" to key code "124"\'' ); 

The complete function is like this

 

function keyPress(os){
    // #target photoshop
    // app.bringToFront();
    // 123 left
    // 124 right
    // 126 up
    // 125 down
    // 116 PgUp
    // 121 PgDn
    // 115 Home
    // 119 End
    
    // alert(os)
    // $.sleep (100);
    // Check OS
    if (os == "Windows") {
      // WIP get windows equilant code
    } else if (os == "Mac") {
        // alert(os)
        app.system( 'osascript -e \'tell application "System Events" to key code "124"\'' ); 
        // app.system( 'osascript -e \'tell application "System Events" to key code "123" using command down\'' );
    }
}

 

Known Participant
April 10, 2020

What are you trying to do?  I imagine if you can do it in Javascript, you can do it in ExtendScript.

Have you messed with Mouse/keyboard listeners before?

Adirai Maji
Inspiring
April 11, 2020

I'm not asking about Mouse/Keyboard Listerners.  I don't want to press any key in keyboard and ExtendScript to detect it. I want to press a button in UI and ExtendScript simulate the assigned key for that button. Simply saying I want to create a on screen keyboard like script. Is it possible in ExtendScript?????