Key
Static Properties
Key.modifiersThe current state of the keyboard modifiers.
Type:
ObjectOptions:
modifiers.shift: Boolean—trueif the shift key is pressed,falseotherwise.modifiers.control: Boolean—trueif the control key is pressed,falseotherwise.modifiers.alt: Boolean—trueif the alt/option key is pressed,falseotherwise.modifiers.meta: Boolean—trueif the meta/windows/command key is pressed,falseotherwise.modifiers.capsLock: Boolean—trueif the caps-lock key is active,falseotherwise.modifiers.space: Boolean—trueif the space key is pressed,falseotherwise.modifiers.option: Boolean—trueif the alt/option key is pressed,falseotherwise. This is the same asmodifiers.altmodifiers.command: Boolean—trueif the meta key is pressed on Mac, or the control key is pressed on Windows and Linux,falseotherwise.
Static Methods
Key.isDown(key)Checks whether the specified key is pressed.
Parameters:
key:String— any character or special key descriptor:‘enter’,‘space’,‘shift’,‘control’,‘alt’,‘meta’,‘caps-lock’,‘left’,‘up’,‘right’,‘down’,‘escape’,‘delete’, …Returns:
Boolean—trueif the key is pressed,falseotherwise
Example:Whenever the user clicks, create a circle shaped path. If the 'a' key is pressed, fill it with red, otherwise fill it with blue:
function onMouseDown(event) { var path = new Path.Circle(event.point, 10); if (Key.isDown('a')) { path.fillColor = 'red'; } else { path.fillColor = 'blue'; } }
Was this helpful?