Photoshop Event Manager: Listen for key pressed to execute script
I am trying to write a script that lets me switch between the lasso tool and eyedropper by hitting the SHIFT key. This is my try so far (code taken from Adobe forums and modified, I myself have minimal programming experience):
#target photoshop
if(ScriptUI.environment.keyboardState['shiftKey']){
if (getTool() == 'lassoTool') {
setTool('eyedropperTool');
alert("Your message here...")
} else if (getTool() == 'eyedropperTool') {
setTool('lassoTool');
}
}
function getTool(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var cTool = typeIDToStringID(executeActionGet(ref).getEnumerationType(stringIDToTypeID('tool')));
return cTool;
}
function setTool(tool) {
var desc9 = new ActionDescriptor();
var ref7 = new ActionReference();
ref7.putClass( app.stringIDToTypeID(tool) );
desc9.putReference( app.charIDToTypeID('null'), ref7 );
executeAction( app.charIDToTypeID('slct'), desc9, DialogModes.NO );
}
I have added this script to the Photoshop Event Manager. I have set the Photoshop Event that triggers the script to "everything" in the dropdown menu. Unfortunately, the script only executes when I do a selection while pressing SHIFT. Instead, I would like the script to run every time I press shift. Is that possible?
Thanks!