This block is used for working with keyboard input.
| Element | Usage | Description |
|---|---|---|
| codes | JS |
Provides an object with a set of constant names for frequently used keyboard codes. |
| Element | Name | Type |
|---|---|---|
| codes | BACKSPACE | String |
| TAB | String |
|
| ENTER | String |
|
| CAPS_LOCK | String |
|
| ESC | String |
|
| SPACE | String |
|
| PAGE_UP | String |
|
| PAGE_DOWN | String |
|
| END | String |
|
| HOME | String |
|
| LEFT | String |
|
| UP | String |
|
| RIGHT | String |
|
| DOWN | String |
|
| INSERT | String |
|
| DELETE | String |
The block is implemented in:
jscodes elementProvides an object with a set of constant names for frequently used keyboard codes.
Type: String.
The name values (object properties) are the key codes. Using meaningful names instead of the key codes makes the code easier to understand.
For example, the _onKeyDown method uses the names of the UP and DOWN keys when checking the keyCode field for an event object:
modules.define('input', ['i-bem-dom', 'keyboard__codes'], function(provide, bemDom, keyCodes) {
provide(bemDom.declBlock(this.name, /** @lends input.prototype */{
onSetMod : {
js : {
inited : function() {
this._domEvents().on('keydown', this._onKeyDown);
}
}
},
_onKeyDown : function(e) {
if((e.keyCode === keyCodes.UP || e.keyCode === keyCodes.DOWN) && !e.shiftKey) {
// ...
}
}
}));
});
The following properties are available:
BACKSPACETABENTERCAPS_LOCKESCSPACEPAGE_UPPAGE_DOWNENDHOMELEFTUPRIGHTDOWNINSERTDELETE