How to simulate keyboard (event) press in Photoshop extendscript?
Copy link to clipboard
Copied
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
Explore related tutorials & articles
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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

Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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)
Fair enough.
Did any of the threads provide a solution for your platform?
Copy link to clipboard
Copied
thanks, but no luck yet!
Ben

