How to take the character from the keyboard using jquery?
Answers
Answered by
0
I am trying to retrieve the character inserted into a textfield/input with jQuery.
I use the usual:
var character = String.fromCharCode( e.keyCode || e.which );
method, but the only problem occurs when I use a different keyboard layout which I just noticed.
So for example, on a Standard US Keyboard it works perfectly. On a German Keyboard for instanece, if I have the language set to English - basically rendering it a standard US Keyboard, when I press the characters equivalent to :;'\,./[]=-, I get the German characters I actually see on my keyboard (although the English equivalent of then is added to the input).
Example: if I console.log( character ) for the folowing sentence I get:
In the input: []\';/.,In the console: ÛݺÞܼ¾¿
My obvious question is, how can I make sure to get the true character inserter
I use the usual:
var character = String.fromCharCode( e.keyCode || e.which );
method, but the only problem occurs when I use a different keyboard layout which I just noticed.
So for example, on a Standard US Keyboard it works perfectly. On a German Keyboard for instanece, if I have the language set to English - basically rendering it a standard US Keyboard, when I press the characters equivalent to :;'\,./[]=-, I get the German characters I actually see on my keyboard (although the English equivalent of then is added to the input).
Example: if I console.log( character ) for the folowing sentence I get:
In the input: []\';/.,In the console: ÛݺÞܼ¾¿
My obvious question is, how can I make sure to get the true character inserter
Similar questions
Computer Science,
7 months ago
Biology,
7 months ago
Math,
1 year ago
Math,
1 year ago
Science,
1 year ago