1

I'm wondering how to safely see if the < and > keys are pressed in jQuery. It's 226 on my Swedish keyboard, but we're having the < and > keys on the same key, and using shift to select which one.

How can I safely determine which is pressed without having to worry about localization, American keyboard have the keys on two different ones?

Conrad Frix
  • 51,984
  • 12
  • 96
  • 155

1 Answers1

0

You should use the keypress event and the .which.

See jQuery Event Keypress: Which key was pressed? A-Z, & @ for more information.

.which gives the character code, as opposed to the keycode. < and > are symbols and shouldn't be effected by localization as certain letters are.

Community
  • 1
  • 1
Andrew Grothe
  • 2,562
  • 1
  • 32
  • 48
  • Well, I want to know the the keys `<` and `>` are pressed, not if the key with the keyCode 226 is pressed. The US keyCode for `<` for example is 188. So I can't really rely on the keyCode. –  Mar 14 '13 at 19:46
  • Right, keypress gives you a charCode, not a keyCode. See this answer as well: http://stackoverflow.com/questions/4285627/javascript-keycode-vs-charcode-utter-confusion – Andrew Grothe Mar 15 '13 at 10:48