Handle modifier key on button click

Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: Tom, Kukurykus

Mike Hale

Handle modifier key on button click

Post by Mike Hale »

I just noticed ScriptUI.environment.keyboardState in the tools guide and thought I would post an example of how to have a button respond to modifier keys.

Code: Select allvar dlg = new Window( 'dialog', 'Modifer key Button click Example' );
dlg.btnRun = dlg.add('button',undefined,'buttonText');
dlg.btnRun.onClick = function(){
   var keyState = ScriptUI.environment.keyboardState;
   if(keyState.shiftKey) alert('do shift click');
   if(keyState.ctrlKey) alert('do ctl click');
   if(keyState.altKey) alert('do alt click');
   if(keyState.metaKey) alert('do meta click');
   if(!keyState.shiftKey && !keyState.ctrlKey &&
      !keyState.altKey && !keyState.metaKey) alert('do standard click');
}
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' });

dlg.show();
txuku

Handle modifier key on button click

Post by txuku »

It's cool Mike Hale !