forked from madrobby/keymaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
89 lines (74 loc) · 2.65 KB
/
test.html
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<html>
<head>
<title>The Keymaster</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<script src="keymaster.js"></script>
<h1>
The Keymaster
</h1>
<input type="text" placeholder="a text input"/>
<select><option></option><option>select</option></select>
<textarea placeholder="a textarea"></textarea>
<ol>
<li>Press 'c'. Nothing should be logged on console.</li>
<li>Press 'o' or Enter or Cursor ←. Console should log function call.</li>
<li>Press 'i'. Switches scope to 'issues'.</li>
<li>Press 'c'. Console should log function call.</li>
<li>Press 'o' or Enter or Cursor ←. Console should log function call.</li>
<li>Press and hold 'm'. Console should log a message every second.</li>
<li>Every second console should log a message listing all the currently pressed keycodes.</li>
</ol>
<p>
At any time, try pressing ⌘+right, shift+left or ctrl+shift+alt+d.
</p>
<p>
When a input, a select or a textarea element is focused, key inputs should be ignored.
</p>
<script>
key('c', 'issues', function(){
console.log('c/issues');
});
key('command+r, ctrl+r', 'issues', function(){
console.log('Hijacked Command+R or Ctrl+R, damn!');
return false;
});
key('i', function(){
key.setScope('issues');
console.log('Switched to "issues" scope. Command+R or Ctrl+R is now no longer reloading...');
});
key('i', function(){
console.log('(example of multiple assignment)');
});
key('o, enter, left', function(){
console.log('o, enter or left pressed!');
});
key('ctrl+c', function(){
console.log('this is not the command line');
});
key('⌘+right,shift+left,ctrl+shift+alt+d', function(event){
console.log('command+right, or shift+left, or ctrl+shift+alt+d');
console.log('here is the event: ', event);
console.log('key.control', key.control);
console.log('key.ctrl', key.ctrl);
console.log('key.shift', key.shift);
console.log('key.alt', key.alt);
console.log('key["⌘"]', key["⌘"]);
return false; // prevent default && stop propagation
});
key('⌘+x, ctrl+x', function(event, handler){
console.log(handler.shortcut, handler.scope);
return false;
});
key('/', function(){ console.log('/') });
key('shift+]', function(){ console.log('shift+]') });
setInterval(function () {
console.log('All keys currently down: ' + key.getPressedKeyCodes());
if (key.isPressed(77)) {
console.log('M key is currently down');
}
}, 1000);
</script>
</body>
</html>