Last active
August 29, 2015 14:16
-
-
Save r4fx/1b56ecd4b7b0eb950111 to your computer and use it in GitHub Desktop.
Events on keybord keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var keys = {}; | |
$(document).keydown(function (e) { | |
keys[e.which] = true; | |
showThemeSelector(e); | |
}); | |
$(document).keyup(function (e) { | |
delete keys[e.which]; | |
showThemeSelector(e); | |
}); | |
function showThemeSelector(e) { | |
var key = String.fromCharCode(e.keyCode); | |
for (var i in keys) { | |
if (!keys.hasOwnProperty(i)) continue; | |
console.log(i, key); | |
} | |
// if the user pressed 'R + T': | |
if (keys[82] == true && keys[84] == true) { | |
$('.themeSelect').toggleClass('active'); | |
} | |
// if the user pressed 'ctrl + t': | |
if ((e.metaKey || e.ctrlKey) && e.which == 84) { | |
$('.themeSelect').toggleClass('active'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment