Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out the character pressed key

If I add a listener to KeyboardEvent.KEY_DOWN, I can find out the keyCode and the charCode.

The keyCode maps to a different character depending on the keyboard.

The charCode is just as useless, according to the help:

The character code values are English keyboard values. For example, if you press Shift+3, charCode is # on a Japanese keyboard, just as it is on an English keyboard.

So, how can I find out which character the user pressed?

like image 713
Andres Avatar asked Apr 14 '09 18:04

Andres


People also ask

How do you figure out what key is being pressed?

Visit Keyboard Checker and tap the key you want to test. If a key on the on-screen keyboard turns green, that means the keypress is being recognized however, the keyboard you see is NOT going to be an accurate representation of the keyboard you're using.

Which key is pressed in JavaScript?

There are three different keyboard events in JavaScript: keydown : Keydown happens when the key is pressed down, and auto repeats if the key is pressed down for long. keypress : This event is fired when an alphabetic, numeric, or punctuation key is pressed down. keyup : Keyup happens when the key is released.

How do you check if key pressed is Enter key?

to check if the key with key code 13 is pressed. If it is, then we know the enter key is pressed.

How do you unlock characters in Keydown event?

keydown and keyup provide a code indicating which key is pressed, while keypress indicates which character was entered. Using jQuery e. which you can get the key code and using String. fromCharCode you can get the specific character that was pressed (including shiftKey ).


1 Answers

You left out a pretty important part of the quote or it was missing where you found it:

For example, if you press Shift+3, the getASCIICode() method returns # on a Japanese keyboard, just as it does on an English keyboard.

http://livedocs.adobe.com/flex/201/langref/flash/events/KeyboardEvent.html

This is probably more helpful:

The charCode property is the numeric value of that key in the current character set (the default character set is UTF-8, which supports ASCII).

http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000480.html

Your application determines what characters set is used, meaning that the even if you have to use separate keys of different keyboard locals to produce the same character, it will have the same charCode.

like image 169
Stiggler Avatar answered Sep 30 '22 12:09

Stiggler