Remembering syntax for this kind of actions is not my strongest point.
My solution: create a global method which you can call easy and a boolean in return.
//get the last key modifiers of last user action (shift = 1,ctrl = 2,meta = 4,alt = 8 )
var $key = arguments[0]
var m = application.getLastKeyModifiers();
Thanks for this, Marc. Here is a variation that accommodates multiple modifier keys. Pass it a string of mod key names delimited with the | character. It works for just a single mod key too:
var vKey = arguments[ 0 ];
var vKeyArray = vKey.split( "|" );
var m = application.getLastKeyModifiers();
var i = 0;
if ( plugins.it2be_tools.arrayContains( vKeyArray, "shift" ) )
{
i += 1;
}
if ( plugins.it2be_tools.arrayContains( vKeyArray, "ctrl" ) )
{
i += 2;
}
if ( plugins.it2be_tools.arrayContains( vKeyArray, "meta" ) )
{
i += 4;
}
if ( plugins.it2be_tools.arrayContains( vKeyArray, "alt" ) )
{
i += 8;
}
if ( i == 0 )
{
i = "error";
}
//offset for pc/mac values
if ( m >= 16 )
{
m -= 16;
}
return ( m & i ) == i;
Oops. My method doesn’t exactly work for multiple keys if you evaluate with a bitwise operator. It will work if you use:
return m == i;
instead of
return (m & i) == i;
If I only want to return a true value in the case when a single key is pressed and not a combination of keys that include the single key, is there any reason why a bitwise operator is needed?