Skip to main content
Participating Frequently
February 11, 2016
Question

Send keystroke from Javascript to Photoshop ?!

  • February 11, 2016
  • 2 replies
  • 4229 views

Is it possible to send keystrokes from Javascript to Photoshop ?

I write a HTML5/Javascript panel. E.g. if I want to simulate a keystroke as "5", "50" or "altG"

which changes e.g. the opacity of a brush. Is there a way in javascript, maybe jQuery to send keystrokes to photoshop?

This topic has been closed for replies.

2 replies

Inspiring
February 12, 2016

If you want to mimic the pressing of a key you can just run a vbs script or a .command on mac to send a keystroke.

if(IsWindowsOS()){

  var mb_keystrF = new File(File($.fileName).path +"/kestr.vbs");

    var str = 'WScript.Sleep 1500\

Set WshShell = WScript.CreateObject("WScript.Shell")\

WshShell.SendKeys "5"\

WScript.Sleep 1500\

WshShell.SendKeys "%g"';

    mb_keystrF.open('w');

    mb_keystrF.write(str);

    mb_keystrF.close();

  mb_keystrF.execute();

}

if(IsMacintoshOS()){

  var mb_keystrF = new File(File($.fileName).path +"/kestr.command");

    var str = 'echo\'\

delay 1.5\

tell application "Photoshop" to activate\

delay 0.1\

tell application "System Events" to keystroke "5"\

delay 0.1\

tell application "System Events" to keystroke "g" using option down\

delay 0.02\

\' | osascript';

    mb_keystrF.open('w');

    mb_keystrF.write(str);

    mb_keystrF.close();

    mb_keystrF.execute();

}

function IsMacintoshOS() {

    if ( $.os.search(/macintosh/i) != -1 ) {

        return true;

    } else {

        return false;

    }

}

function IsWindowsOS() {

    if ( $.os.search(/windows/i) != -1 ) {

        return true;

    } else {

        return false;

    }

}

tssee
Inspiring
February 12, 2016

I have this error

permission I checked them and are just

Unable to "kestr.command" file because you do not have appropriate access privileges.

how can I fix

Inspiring
February 12, 2016

By default the.command files are not executable you just have to run this command in your terminal:

chmod +x path to your file keystr.command

Chuck Uebele
Community Expert
February 11, 2016

There might be, but I think only some keys can be captured due to security threats of key logging. People don't want scripts that can capture what they type.

Participating Frequently
February 11, 2016

I do not want to capture what people type. If I press a certain button in a panel, I want the javascript to send the according keystroke to Photoshop. As the user would type it by hand. This is to change e.g. opacity, blend modes of the brush/clonestamp tool by a button in a HTML5 panel.As I did not figure out how to change the opacity/blendmode dirctly within javascript, emulating the according keystrokes may be an alternative.

Chuck Uebele
Community Expert
February 11, 2016

Misunderstood, going the other way.