Page 3 of 3

Re: not unique keyboard scancodes

Posted: Sun Nov 25, 2012 11:03 am
by Brendan
Hi,
zgintasz wrote:
egos wrote:Heh, what you want that you get :lol:
single scancode, not many scancodes on key press. For example if I press home key, I get these scancodes: 224 108 224 240 108(224, 108 and 224 when key is pressed, 240 and 108 when key is released). So how to make if sentence to get unique and single(single = 1, many = more than 1) scancode, so I can write keyboard ascii map - I can't write it now, because I get not single scancode on key press. Hope you understood.
You need to convert the (multi-byte) scan-codes into a unique single-byte "key code"?

First step would be implementing a state machine in your IRQ handler. For example, if you get "0xE0" you set a flag, if you get "0xE1" you set a different flag, if you get "0xF0" you set another different flag, etc.

Once that's done you can start working on normal keys. For example, if you receive "0x4A" you check the flag for "0xE0" to determine if the key is '/' on the main keyboard or '/' on the keypad; then check the flag for "0xF0" to determine if it was pressed or released. This is mostly just a big table lookup (e.g. "keycode = myTable[flags][scancode]"). Of course you'd have to invent some sort of meaning for your OS's "key codes" (and document it).

Once you've done that you'd have a bit for each key (saying if that key is currently pressed or not), and set the corresponding key's bit. Then (for most keys) you'd use this "bit for each key" to determine if a shift key, alt key, control key, etc was pressed at the same time. This is the beginning of converting you key-code to Unicode; which depends on which keyboard layout is currently being used.

At the end you'd have some sort of "keypress packet" containing a lot of information - e.g. which keycode, if it was pressed/released, which Unicode codepoint (if any), the states of various meta-keys (shift, alt, etc) and the states of various toggles (caps lock, num lock, etc). You'd use your OS's normal IPC (whatever that is) to send the entire "keypress packet" to wherever it's meant to go.

The main point is; nobody is going to write all this for you. You need to write your OS yourself.


Cheers,

Brendan

Re: not unique keyboard scancodes

Posted: Sun Nov 25, 2012 12:07 pm
by egos
zgintasz wrote:single scancode, not many scancodes on key press. For example if I press home key, I get these scancodes: 224 108 224 240 108(224, 108 and 224 when key is pressed, 240 and 108 when key is released). So how to make if sentence to get unique and single(single = 1, many = more than 1) scancode, so I can write keyboard ascii map - I can't write it now, because I get not single scancode on key press. Hope you understood.
As I said above, prefixes 0xE0, 0xE1 exist in set 1 as well as in set 2. So you can't have always 1-byte "make" code anyway. As to the "break" prefix (0xF0), to use it is not more hard than "break" flag in set #1.