1

In JavaScript, on a keydown or keypress event, is there a way to determine the character that would have got typed if the shift key was pressed down as well (irrespective of whether the shift key is actually held down at the time)

E.g: if the keydown corresponds to '1', I need to get '!'

This would depend on the keyboard type as well. So, is there a way to factor that in too?

Himanshu P
  • 9,586
  • 6
  • 37
  • 46

1 Answers1

0

Theoretically, keypress events should give the character representing the key you have pressed (which is what you are aiming at), however the implementation on browsers vary (yes, it's 2013 and we're still at that).

See the answer on this question

Community
  • 1
  • 1
Jcl
  • 27,696
  • 5
  • 61
  • 92
  • I know that the `keypress` event, which is also tagged, does that but I want to get the character "irrespective of whether the `shift` key is actually held down at the time" :) – Himanshu P Sep 09 '13 at 07:21
  • Oh, I see, sorry, I understood the question completely wrong. There's (this)[http://www.selfcontained.us/2009/09/16/getting-keycode-values-in-javascript/] but it doesn't take into account different keyboard layouts (or all the keys, for the matter). I don't think there's a good way to do what you want in Javascript (since the keyboard layout is defined by the system, not the browser), but I might be wrong. – Jcl Sep 09 '13 at 07:22