The Little Guy Posted February 8, 2008 Share Posted February 8, 2008 OK, I have this function: It checks to see if the enter key was pressed. How do I check to see if shift + enter was pressed? function hitkey(event) { if (event.keyCode == 13) { alert(event.keyCode); } } Quote Link to comment Share on other sites More sharing options...
nogray Posted February 8, 2008 Share Posted February 8, 2008 the event should have an object to hold the shift key status event.shiftKey event.shiftLeft http://msdn2.microsoft.com/en-us/library/ms536939(VS.85).aspx Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 8, 2008 Author Share Posted February 8, 2008 Thank you result: function hitkey(event) { var sPressed; if(event.shiftKey){ sPressed = true; }else{ sPressed = false; } if (event.keyCode == 13 && !sPressed) { alert('send'); } } Quote Link to comment Share on other sites More sharing options...
emehrkay Posted February 8, 2008 Share Posted February 8, 2008 does event.shiftKey work crossbrowser? You may want to check that //this is what i added to firebug and shift is never logged function hitkey(event) { console.log(event); var sPressed; if(event.shiftKey){ console.log('shift'); }else{ sPressed = false; } if (event.keyCode == 13 && !sPressed) { alert('send'); } } window.onkeyup = function(e){ hitkey(e); }; Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 8, 2008 Author Share Posted February 8, 2008 it comes from Microsoft (so it should work in IE), and it works in Firefox, because that is where I tested it. Quote Link to comment Share on other sites More sharing options...
emehrkay Posted February 8, 2008 Share Posted February 8, 2008 well the reason why it works in firefox is because your logic is flawed. you want to check if shift and enter is pressed, but you never define sPressed as boolean and sPressed never changes in firefox so !sPressed returns true. Run the code that i posted, you never get 'shift' in the log when shift is pressed Do a search, possibly quirskmode will be your best resource, for crossbrowser keycodes and how to check for them Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.