How to find which key is pressed, not which character it will be?

139 Views Asked by At

I need to find out which key was pressed, not what character it would be.

For example, I want after pressing 'a' a number such (1) create so I can map it to other languages. In common way we can find it is 'a' or we can have it's hash code, but is it possible to have char or hash code in a language and find out what char or hash code it would be in another language?

Attention some language have not the standard keyboard so pressing a key not mean a certain character.

1

There are 1 best solutions below

0
On

There's no reason to do this in any language i've seen.

(besides the fact that you didn't specify in which language you are trying to achieve this) All languages allow you to get the character code from a keypress. If you know which encoding was used (UTF 8, Ascii, you name it), it's trivial to map the code to the actual character.

Assigning a different keyboard layout on OS level means that it no longer matters which keyboard layout you are using.

if you have a QWERTY keyboard, switch it to AZERTY and press the button where the q would be, you get an a, despite the letters on the keyboard still saying QWERTY.

If you are using a chinese keyboard, the characters no longer map to any western set, so the character codes will not match up with UTF8 or ASCII, but CP963 (or another chinese codepage, depending on several factors), which is so different there is no real way to translate it to UTF8 or ASCII.