mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Simplify Key further and fix ToolEvent#getModifiers.
This commit is contained in:
parent
404bbac3a5
commit
778997ec18
2 changed files with 6 additions and 10 deletions
|
@ -192,7 +192,7 @@ var ToolEvent = this.ToolEvent = Base.extend({
|
|||
},
|
||||
|
||||
getModifiers: function() {
|
||||
Key.modifiers;
|
||||
return Key.modifiers;
|
||||
}
|
||||
|
||||
// TODO: implement hitTest first
|
||||
|
|
|
@ -19,7 +19,7 @@ var Key = new function() {
|
|||
|
||||
var activeKeys = {};
|
||||
|
||||
var modifiers = this.modifiers = {
|
||||
var modifiers = {
|
||||
shift: false,
|
||||
control: false,
|
||||
alt: false,
|
||||
|
@ -32,13 +32,8 @@ var Key = new function() {
|
|||
keyDown = type == 'keyDown';
|
||||
this[type.toLowerCase()] = function(event) {
|
||||
var code = event.which || event.keyCode,
|
||||
key = keys[code] || String.fromCharCode(code).toLowerCase(),
|
||||
keyActive = activeKeys[key];
|
||||
if (!keyActive && keyDown) {
|
||||
activeKeys[key] = true;
|
||||
} else if (keyActive && !keyDown) {
|
||||
delete activeKeys[key];
|
||||
}
|
||||
key = keys[code] || String.fromCharCode(code).toLowerCase();
|
||||
activeKeys[key] = keyDown;
|
||||
|
||||
// If the key is a modifier, update the modifiers:
|
||||
if (modifiers[key] !== undefined)
|
||||
|
@ -54,11 +49,12 @@ var Key = new function() {
|
|||
modifiers: modifiers
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}, {});
|
||||
Event.add(document, eventHandlers);
|
||||
|
||||
return {
|
||||
modifiers: modifiers,
|
||||
isDown: function(key) {
|
||||
return !!activeKeys[key];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue