paper.js/src/ui/KeyEvent.js

65 lines
1.4 KiB
JavaScript
Raw Normal View History

/*
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
2014-01-03 19:47:16 -05:00
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
2011-07-01 06:17:45 -04:00
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
/**
* @name KeyEvent
*
2012-12-23 10:01:53 -05:00
* @class The KeyEvent object is received by the {@link Tool}'s keyboard
* handlers {@link Tool#onKeyDown}, {@link Tool#onKeyUp}. The KeyEvent object is
* the only parameter passed to these functions and contains information about
* the keyboard event.
*
* @extends Event
*/
var KeyEvent = Event.extend(/** @lends KeyEvent# */{
_class: 'KeyEvent',
initialize: function KeyEvent(down, key, character, event) {
Event.call(this, event);
2011-11-16 16:54:03 -05:00
this.type = down ? 'keydown' : 'keyup';
this.key = key;
this.character = character;
},
2011-05-23 13:56:18 -04:00
2011-11-16 16:54:03 -05:00
/**
* The type of key event.
*
* @name KeyEvent#type
* @type String('keydown', 'keyup')
*/
2011-05-23 13:56:18 -04:00
2011-11-16 16:54:03 -05:00
/**
* The string character of the key that caused this key event.
*
* @name KeyEvent#character
* @type String
*/
2011-05-23 13:56:18 -04:00
2011-11-16 16:54:03 -05:00
/**
* The key that caused this key event.
*
* @name KeyEvent#key
* @type String
*/
2011-05-23 13:56:18 -04:00
2011-11-16 16:54:03 -05:00
/**
2013-08-23 22:45:28 -04:00
* @return {String} a string representation of the key event
2011-11-16 16:54:03 -05:00
*/
toString: function() {
2012-12-08 22:57:04 -05:00
return "{ type: '" + this.type
+ "', key: '" + this.key
+ "', character: '" + this.character
+ "', modifiers: " + this.getModifiers()
+ " }";
2011-11-16 16:54:03 -05:00
}
});