Відповіді:
Він являє собою bitmaskподії, підтримувані пристроєм.
Зразок devicesзапису для клавіатури AT:
I: Bus=0011 Vendor=0001 Product=0001 Version=ab41
N: Name="AT Translated Set 2 keyboard"
P: Phys=isa0060/serio0/input0
S: Sysfs=/devices/platform/i8042/serio0/input/input2
U: Uniq=
H: Handlers=sysrq kbd event2
B: PROP=0
B: EV=120013
B: KEY=20000 200 20 0 0 0 0 500f 2100002 3803078 f900d401 feffffdf ffefffff ffffffff fffffffe
B: MSC=10
B: LED=7
BУ передніх стійок для bitmap, N, P, S, U, Hпросто перший лист до відповідного значення імені і Iдля ID. Впорядкованим способом:
I => @id: id of the device (struct input_id)
Bus => id.bustypeVendor => id.vendorProduct => id.productVersion => id.versionN => name of the device.P => physical path to the device in the system hierarchy.S => sysfs path.U => unique identification code for the device (if device has it).H => list of input handles associated with the device.B => bitmaps
PROP => device properties and quirks.EV => types of events supported by the device.KEY => keys/buttons this device has.MSC => miscellaneous events supported by the device.LED => leds present on the device.Як ви знаєте, комп'ютери мають справу в двійковому форматі:
1 = 0001
2 = 0010
3 = 0011
4 = 0100
5 = 0101
...
Отже, якщо у мене є растровий малюнок зі значенням, 5який би містив біти 0 і 2, іншим словом, можна дати кожному імені і перевірити, чи відповідають вони значенню.
Напр
A = 1, 001
B = 2, 010
C = 4, 100
Тоді, якщо у мене є те, MYVAR = 5що є 101в двійковому, це перевірить:
MYVAR & A == TRUE (101 & 001 => 001)
MYVAR & B == FALSE (101 & 010 => 000)
MYVAR & C == TRUE (101 & 100 => 100 )
Таким чином, мій var має A і C.
Ядро використовує дещо складніший / складніший спосіб і встановлює біти шляхом зміщення. Однією з причин є те, що в одному комп’ютері (процесорі) використовується ціле число бітів. Наприклад, подивіться на KEYрастрову карту.
Отже, якщо ми скажемо:
A = 0
B = 1
C = 6
...
І потім
target = 0;
set_bit(A, target); => target == 0001
set_bit(C, target); => target == 0100 0001
120013Значення 120013- шістнадцяткове. Як двійкове воно дає нам:
0x120013 == 0001 0010 0000 0000 0001 0011 binary
1 2 0 0 1 3
Нумерацією справа вони:
2 1 <= offset (10's)
3210 9876 5432 1098 7654 3210 <= offset (counted from right)
0001 0010 0000 0000 0001 0011 <= binary
Set bits are:
0, 1, 4, 17, 20
Потім перевірте input.h, чи відповідають вони:
0 EV_SYN (0x00)
1 EV_KEY (0x01)
4 EV_MSC (0x04)
17 EV_LED (0x11)
20 EV_REP (0x14)
Щоб перевірити, що вони означають швидке введення, надано Документація ядра .
* EV_SYN:
- Used as markers to separate events. Events may be separated in time or in
space, such as with the multitouch protocol.
* EV_KEY:
- Used to describe state changes of keyboards, buttons, or other key-like
devices.
* EV_MSC:
- Used to describe miscellaneous input data that do not fit into other types.
* EV_LED:
- Used to turn LEDs on devices on and off.
* EV_REP:
- Used for autorepeating devices.
Це, зокрема , "EDIT 2 (продовження):" може представляти інтерес.
0x120013, але як мінімум. Ви не хочете робитиif(ev == 0x120013){ isKeyboard = true; }, ви хотіли б це зробитиif((ev & 0x120013) == 0x120013){ isKeyboard = true; }