-
Notifications
You must be signed in to change notification settings - Fork 0
/
key-check.js
52 lines (39 loc) · 925 Bytes
/
key-check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
determine if certain keys are being pressed utility
*/
var utils = utils || {};
(function() {
// checks if the tab key was pressed
function tab(e) {
var key = e.keyCode || e.which;
return key === 9 || key === '9';
}
// checks if the enter key was pressed
function enter(e) {
var key = e.keyCode || e.which;
return key === 13 || key === '13';
}
// checks if the escape key was pressed
function esc(e) {
var key = e.keyCode || e.which;
return key === 27 || key === '27';
}
// checks if the up key was pressed
function up(e) {
var key = e.keyCode || e.which;
return key === 38 || key === '38';
}
// checks if the down key was pressed
function down(e) {
var key = e.keyCode || e.which;
return key === 40 || key === '40';
}
var keys = {
enter: enter,
tab: tab,
esc: esc,
up: up,
down: down
};
utils.keys = keys;
}());