Keydown event for modifier keys

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

timroes

Keydown event for modifier keys

Post by timroes »

Hi,

I recognized, that the keydown events (e.g. on a Window) aren't fired for pressing some modifier key (e.g. Alt, Shift, ...).
Is there a way to listen to keydown of the modifier keys, without any other key is getting pressed? Since I already want to change
some state in the UI, as soon as the user presses the Alt-key.

Regards, Tim

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mike Hale

Keydown event for modifier keys

Post by Mike Hale »

What version are you using? It seems that keyboard and mouse event have some problems in Photoshop CS5.

For example the code below works as expected in ESKT with ESTK set as the target. But switch the target to Photoshop and it no longer works.
Code: Select allcreateDialog = function ( ) {
   var dlg = new Window( 'dialog', 'MetaKey Event Example' );
   dlg.addEventListener ('keydown', InitEditKeyboardHandler );
   dlg.addEventListener ('keyup', InitEditKeyboardHandler );
   dlg.stNotice = dlg.add('statictext',undefined,'Some default instructions');
   dlg.btnPnl = dlg.add( 'panel', undefined );
   dlg.btnPnl.orientation = "row";
   dlg.btnPnl.alignment = "right";
   dlg.btnPnl.preferredSize [ 80, 80 ]
   dlg.btnPnl.okBtn = dlg.btnPnl.add( 'button', undefined, 'Ok', { name:'ok' });
   dlg.btnPnl.cancelBtn = dlg.btnPnl.add( 'button', undefined, 'Cancel', { name:'cancel' });
   return dlg;
};
initializeDialog = function( w ) {
   // Set up initial control states
 }

runDialog = function( w ) {
   return w.show( );
};
var win = createDialog();
initializeDialog(win);
runDialog(win);

function InitEditKeyboardHandler (event) {
   try {
      switch( event.keyName ){
         case 'Alt':
               win.stNotice.text = 'Alt key instructions'; break;
         case 'Control':
               win.stNotice.text = 'Ctrl key instructions'; break;
         case 'Shift':
               win.stNotice.text = 'Shift key instructions'; break;
         default: win.stNotice.text = 'Some default instructions';
      }
   if(event.type == 'keyup') win.stNotice.text = 'Some default instructions';
   }catch (e){}
};
timroes

Keydown event for modifier keys

Post by timroes »

Yeah I am using exactly Photoshop CS5 ... That's sad.