Skip to main content
photogyulai
Inspiring
April 29, 2016
Question

How to simulate keyboard (event) press in Photoshop extendscript?

  • April 29, 2016
  • 1 reply
  • 2156 views

Hey Guys!

Is it possible to simulate a keyboard event trough script (in Photoshop)?!?

Trough .jsx/html extension?!?

I mean i press a button like:

HTML:

<button class="basic_button" onclick="onClickButton('example_push')">Button Text</button>

lickButton('example_push')">Button Text</button>

Javascript:

$._ext_example_push={

    run : function() {

  //something

  //something

      }

  };

and than some keyboard press is simulated. For example "CTRL+0"  (Fit on Screen command) or any else?!?

Any ideas or examples and/or solutions are more than welcome!!

Thank You!

Ben

This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
April 30, 2016
and than some keyboard press is simulated. For example "CTRL+0"  (Fit on Screen command) or any else?!?

Why insert an unnecessary step (simulating the key-press) for something that can be Scripted anyway?

Simulating key-press events is platform dependent, did you do a Forum Search?

https://forums.adobe.com/search.jspa?q=simulate%20press%20key

Send keystroke from Javascript to Photoshop ?!

photogyulai
Inspiring
April 30, 2016

note the "or any else" part....

but here are my answers and goals:

1. it could be usefull to education

2, it could be usefull when script listener fails you

3. it could be easier than write 100line of code (depending on the key simulator code of course)

thats all :-)
Do You know script for Fit on Screen command (ctrl+0)?!? 

Appreciate any help....
i check out the link You gave me

April 30, 2016

Do You know script for Fit on Screen command (ctrl+0)?!?

From CS4, you can use the built-in app.runMenuItem method:

runMenuItem (stringIDToTypeID ("fitOnScreen"));

runMenuItem (stringIDToTypeID ("actualPixels"));

runMenuItem (stringIDToTypeID ("printSize"));

And before CS4, you can use Action Manager code to define your own runMenuItem function:

function runMenuItem (menuItem)

{

    var desc = new ActionDescriptor ();

    var ref = new ActionReference ();

    ref.putEnumerated (stringIDToTypeID ("menuItemClass"), stringIDToTypeID ("menuItemType"), menuItem);

    desc.putReference (stringIDToTypeID ("target"), ref);

    executeAction (stringIDToTypeID ("select"), desc, DialogModes.ERROR);

}

HTH,

--Mikaeru