Reputation: 3640
I have all other keys set up using shortKeys in JavaScript like so:
<script type="text/javascript" src="http://rikrikrik.com/js/jquery.shortkeys.js"></script>
$(document).shortkeys({
'U': function () {
$('#imginput').slideToggle(500);
$("#textinput").slideUp(500);
$("#sortPost").slideUp(500);
}});
Now I am trying to set up the escape key, but I dont know how.
I tried:
$(document).shortkeys({
'Esc': function () {
$('#imginput').slideUp(500);
$("#textinput").slideUp(500);
$("#sortPost").slideUp(500);
$('.help_info').fadeOut(500);
}});
and I also tried:
e.keyCode == 27: function () {
$('#imginput').slideUp(500);
$("#textinput").slideUp(500);
$("#sortPost").slideUp(500);
$('.help_info').fadeOut(500);
}});
How would I make it so that these events occur when I press escape?
Upvotes: 1
Views: 149
Reputation: 22339
I don't know shortkeys
but using a standard keyup
binding you can do this:
$(document).keyup(function(e) {
if (e.which == 27) {
$('#imginput').slideUp(500);
$("#textinput").slideUp(500);
$("#sortPost").slideUp(500);
$('.help_info').fadeOut(500);
}
});
As noted in the event.which
documentation:
The event.which property normalizes event.keyCode and event.charCode. It is recommended to watch event.which for keyboard key input.
Upvotes: 1