• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

How to simulate a key-press in ExtendScript?

Contributor ,
Apr 09, 2020 Apr 09, 2020

Copy link to clipboard

Copied

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 

TOPICS
How to , Resources , Scripting , SDK

Views

3.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 10, 2020 Apr 10, 2020

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 11, 2020 Apr 11, 2020

Copy link to clipboard

Copied

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?????

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 26, 2020 Apr 26, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 26, 2020 Apr 26, 2020

Copy link to clipboard

Copied

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 16, 2021 Jan 16, 2021

Copy link to clipboard

Copied

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\'' );
    }
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 16, 2021 Jan 16, 2021

Copy link to clipboard

Copied

I was doing Windows, but good to know you had success with this?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 16, 2021 Jan 16, 2021

Copy link to clipboard

Copied

As I want to simulate the keypress just in Ae (regardless of what system is it) I just need the solution for both Windows as well as Mac. Thank you for this piece of code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 17, 2021 Jan 17, 2021

Copy link to clipboard

Copied

I found a better method, this one wont show a flashing command window. First i didnt got it working so i thought something was wrong. Tried it a couple times more and works like a champ, no flashing command window 🙂

 

source from this thread post

 

 

 

try{
    var mb_keystrF = new File(File(getPrefFolder()+'/amd2-shortcut.vbs'));
    var str = 'Set WshShell = WScript.CreateObject("WScript.Shell")\
                WshShell.SendKeys "{RIGHT}"';
    mb_keystrF.open('w');
    mb_keystrF.write(str);
    mb_keystrF.close();
    mb_keystrF.execute();
} catch(e){
    alert(e)
}

 

 

 

The video is perhaps not very clear. But when doing animations and the timeline is zoomed in, its can be quite tedious to use the horizontal scrollbar. Therefor i developed the global time scrubber. Its basically the complete timeline and clicking anywhere will set the playhead to that time and it will jump to that section. That last part is why i needed the keystrokes. Moving the playhead worked, but the timeline does not scroll along. So i set the playhead 1 frame before and use arrow key to move 1 frame. Then it does focus again on the playhead.

 

Example of timeline scrubbingExample of timeline scrubbing

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 17, 2021 Dec 17, 2021

Copy link to clipboard

Copied

LATEST

Hi, I'm trying this in an After Effects ScriptUI panel and get the error :

"ReferenceError: Function getPrefFolder is undefined"

Is there a quick solution?

I desperately need a way to simulate double tap keypresses and also combining CTRL, ALT and SHIFT.

Be grateful for any help.

Cheers!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 04, 2020 May 04, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 04, 2020 May 04, 2020

Copy link to clipboard

Copied

search the tools guide for .notify()

 

...simulates keypress or UI element click. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 08, 2020 Sep 08, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 11, 2020 Sep 11, 2020

Copy link to clipboard

Copied

Here is the documentation for notify() but I don't think that's what you're looking for:

 

http://estk.aenhancers.com/user-interface-tools/window-object.html?highlight=notify#notify

Notify only simulates events in your own tool.

 

If you want to trigger AE UI events, you'll first want to check if it's possible through the API, if not then check if you can access it via commandID (Full Command ID List), if not available there there then search through the C++ API, last resort you can simulate UI events at a system level through 

system.callSystem(), these are different on Mac and PC so look up command line UI simulation for each platform.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines