Keyboard Scancodes?

GNU / Linux text console, X11 not involved, not even installed. Keyboard - American layout, default keyboard layout. kernel version 2.20.x or later.

An application written in C receives keyboard input in translation mode, i.e. XLATEor UNICODE. When a key is pressed, the application receives the corresponding KeyString. For example, you press F1, the application reads "\033[[A".

Before the kernel sends the key to the application, it must know which key is pressed, i.e. he must know his scan code. In the above example, F1 scancode for the key is pressed 59 or 0x3b.

To say it, even when the keyboard is in translation mode, scancodes are stored somewhere in memory. How can applications access them without switching the keyboard to RAWor MEDIUMRAW? The code snippet will help.

+3
source share
4 answers

Most likely, you issue ioctl commands in the wrong file descriptor, check the error codes returned from ioctl and tcsetattr.

You should open a console device, and then issue keyboard commands on that device. You will have to basically simulate what the X server does.

This is a link to the source codesearch.google.com .

+2
source

, , , kbd-1.12.tar.bz2, kbd. "kbd" , "dumpkeys", "showkeys" "loadkeys", , , , scancodes, .

ioctls, , , , .

: kbd-1.12.tar.bz2 (618K).

+1

dumpkeys -f > test.txt

, :

keycode 29 =
...
F1 = "\ 033 [[A"
F2 =" \ 033 [[B "
F3 = "\ 033 [[C "
F4 = "\ 033 [[D "
F5 = "\ 033 [[E "
F6 = "\ 033 [17 ~ "
F7 = "\ 033 [18 ~ "
F8 = "\ 033 [19 ~"
...
string Prior = "\ 033 [5 ~ "
string Next = "\ 033 [6 ~ "
= "\ 033 [M "
string Pause = "\ 033 [P "

dumpkeys . , jerub. kbd-1.12/src/loadkeys.y.

It seems that the kernel is responsible for storing this data and can tell those who know how to ask it.

0
source

You might want to look kbdevor evdev(look at your Documentation/input/input.txtfile in the kernel source directory for starters.) This will work to access the console.

0
source

Source: https://habr.com/ru/post/1697105/


All Articles