Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

94 lines (77 sloc) 2.803 kb
<!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 &larr;. 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 &larr;. 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);
// document.onkeydown = function(event){
// console.log(event.keyCode);
// }
</script>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.