Skip to content

Instantly share code, notes, and snippets.

@r4fx
Last active August 29, 2015 14:16
Show Gist options
  • Save r4fx/1b56ecd4b7b0eb950111 to your computer and use it in GitHub Desktop.
Save r4fx/1b56ecd4b7b0eb950111 to your computer and use it in GitHub Desktop.
Events on keybord keys
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