mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-10 10:25:36 +01:00
27 lines
582 B
JavaScript
27 lines
582 B
JavaScript
import {keymap} from './keymaps/default'
|
|
import {jwerty} from 'jwerty'
|
|
|
|
export function InputManager(app) {
|
|
this.app = app;
|
|
this.keymap = keymap;
|
|
$(() => {
|
|
$(document)
|
|
.on('keydown', (e) => this.handleKeyPress(e))
|
|
});
|
|
}
|
|
|
|
InputManager.prototype.handleKeyPress = function(e) {
|
|
switch (e.keyCode) {
|
|
//case 27 : this.clear(); break;
|
|
}
|
|
|
|
for (let action in this.keymap) {
|
|
if (jwerty.is(this.keymap[action], e)) {
|
|
setTimeout(() => this.app.actions[action].action(e), 0);
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
break;
|
|
}
|
|
}
|
|
};
|
|
|