Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
94 lines (77 sloc) 2.74 KB
<title>The Keymaster</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="keymaster.js"></script>
The Keymaster
<input type="text" placeholder="a text input"/>
<textarea placeholder="a textarea"></textarea>
<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>
At any time, try pressing ⌘+right, shift+left or ctrl+shift+alt+d.
When a input, a select or a textarea element is focused, key inputs should be ignored.
key('c', 'issues', function(){
key('command+r, ctrl+r', 'issues', function(){
console.log('Hijacked Command+R or Ctrl+R, damn!');
return false;
key('i', function(){
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);
// }