I know that the shift key
code is 16
, and the enter key
code is 13
.
//@ catching any 'enter' keypress in textarea.
function textareaOnEnter(){
$('textarea#someId').keypress(function(e)
{
if(e.which == 13)
{
//.. works only for 'enter'
}
});
}
I thought it could be as simple as this:
function textareaOnShiftAndEnter(){
$('textarea#someId').keypress(function(e)
{
if(e.which == 13 && e.which == 16)
{
//.. don't work for nothing
}
});
}
But of course it simply doesn't work as I would expected. How do I check for shift + enter
key press?
I know that the shift key
code is 16
, and the enter key
code is 13
.
//@ catching any 'enter' keypress in textarea.
function textareaOnEnter(){
$('textarea#someId').keypress(function(e)
{
if(e.which == 13)
{
//.. works only for 'enter'
}
});
}
I thought it could be as simple as this:
function textareaOnShiftAndEnter(){
$('textarea#someId').keypress(function(e)
{
if(e.which == 13 && e.which == 16)
{
//.. don't work for nothing
}
});
}
But of course it simply doesn't work as I would expected. How do I check for shift + enter
key press?
- developer.mozilla/en-US/docs/Web/API/KeyboardEvent/shiftKey – Dr.Molle Commented Sep 16, 2015 at 2:08
-
1
e.which
could never be both 13 and 16 at the same time :P. You want modifier keys as @Amadan explains quite succinctly below :) – ChevCast Commented Sep 16, 2015 at 2:11
1 Answer
Reset to default 9if (e.which == 13 && e.shiftKey)
Shift, Ctrl and Alt are modifier keys, that get their own flags in the event data.