mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Also fire key events for modifier keys. Closes #52.
This commit is contained in:
parent
571ca31dbf
commit
a2358a0fc0
1 changed files with 10 additions and 12 deletions
|
@ -93,15 +93,12 @@ var Key = this.Key = new function() {
|
||||||
// a keypress, but space would).
|
// a keypress, but space would).
|
||||||
var key = keys[code], name;
|
var key = keys[code], name;
|
||||||
if (key) {
|
if (key) {
|
||||||
// Do not fire handleKey for modifiers, but for other keys such
|
// Detect modifiers and mark them as pressed
|
||||||
// ass arrows, delete, backspace, etc.
|
if ((name = Base.camelize(key)) in modifiers)
|
||||||
if (modifiers[name = Base.camelize(key)] !== undefined) {
|
|
||||||
modifiers[name] = true;
|
modifiers[name] = true;
|
||||||
} else {
|
// No char code for special keys, but mark as pressed
|
||||||
// No char code for special keys, but mark as pressed
|
charCodeMap[code] = 0;
|
||||||
charCodeMap[code] = 0;
|
handleKey(true, code, null, event);
|
||||||
handleKey(true, code, null, event);
|
|
||||||
}
|
|
||||||
// Do not set downCode as we handled it already. Space would
|
// Do not set downCode as we handled it already. Space would
|
||||||
// be handled twice otherwise, once here, once in keypress.
|
// be handled twice otherwise, once here, once in keypress.
|
||||||
} else {
|
} else {
|
||||||
|
@ -112,8 +109,8 @@ var Key = this.Key = new function() {
|
||||||
keypress: function(event) {
|
keypress: function(event) {
|
||||||
if (downCode != null) {
|
if (downCode != null) {
|
||||||
var code = event.which || event.keyCode;
|
var code = event.which || event.keyCode;
|
||||||
// Link the downCode from keydown with the code form keypress, so
|
// Link the downCode from keydown with the code form keypress,
|
||||||
// keyup can retrieve that code again.
|
// so keyup can retrieve that code again.
|
||||||
charCodeMap[downCode] = code;
|
charCodeMap[downCode] = code;
|
||||||
handleKey(true, downCode, code, event);
|
handleKey(true, downCode, code, event);
|
||||||
downCode = null;
|
downCode = null;
|
||||||
|
@ -123,9 +120,10 @@ var Key = this.Key = new function() {
|
||||||
keyup: function(event) {
|
keyup: function(event) {
|
||||||
var code = event.which || event.keyCode,
|
var code = event.which || event.keyCode,
|
||||||
key = keys[code], name;
|
key = keys[code], name;
|
||||||
if (key && modifiers[name = Base.camelize(key)] !== undefined) {
|
// Detect modifiers and mark them as released
|
||||||
|
if (key && (name = Base.camelize(key)) in modifiers)
|
||||||
modifiers[name] = false;
|
modifiers[name] = false;
|
||||||
} else if (charCodeMap[code] != null) {
|
if (charCodeMap[code] != null) {
|
||||||
handleKey(false, code, charCodeMap[code], event);
|
handleKey(false, code, charCodeMap[code], event);
|
||||||
delete charCodeMap[code];
|
delete charCodeMap[code];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue