/dev/usb/kbd

From WiiBrew
< /dev‎ | usb
Jump to navigation Jump to search

Description

/dev/usb/kbd is the interface to the USB keyboard driver.

Reads, seeks and ioctlvs always fail. Writes are used to send commands. Ioctls are used to receive events.

Write

Writes are used the send commands to the driver. This is for controlling the keyboard LEDs. Writes are always 5 bytes in length.

Available commands:
Write data Function
00 00 00 00 80 Turn off keyboard LEDs.
?? ?? ?? ?? 00 Unknown
?? ?? ?? ?? 00 Unknown
?? ?? ?? ?? 00 Unknown
?? ?? ?? ?? 00 Unknown

Ioctl

Ioctls are used to read keyboard events. All parameters except the output buffer are ignored. The buffer should be 16 bytes in size and will be filled with the event data. Note that the ioctl will block.

Event data format
Offset Length Contents
0 8 Unknown
8 1 Modifiers
9 1 Unknown
10 6 Pressed keys

Modifiers

The modifiers are a bitmask of the following:

Bit no. Hex value Description
1 0x01 Left control
2 0x02 Left shift
3 0x04 Left alt / left meta
4 0x08 Left super / left windows key
Bit no. Hex value Description
5 0x10 Right control
6 0x20 Right shift
7 0x40 Right alt / right meta / alt gr
8 0x80 Right super / right windows key

Key data

The key data is an array of bytes with key codes. These do not seem to match common scancodes, but are more like values in a character table (like ASCII, but not).

Each byte represents a pressed key. When a key is pressed, a new event will arrive with the key added to the array. Once a key is released, a new event will arrive with the key simply removed from the array.

The array is 6 bytes long, so no more than 6 simultaneous key presses can be detected. On top of that, most keyboards will barf on certain combinations. If an error occurs, a new event will arrive with all elements of the array set to 0x01.

Special keys that some keyboards provide seem to be ignored.

The following table of key codes was pulled from a Logitech Internet Navigator keyboard, which is a 105 key US layout keyboard with some special keys:

Dec Hex Description
4 04 a
5 05 b
6 06 c
7 07 d
8 08 e
9 09 f
10 0a g
11 0b h
12 0c i
13 0d j
14 0e k
15 0f l
16 10 m
17 11 n
18 12 o
19 13 p
20 14 q
21 15 r
23 16 s
24 17 t
25 18 u
26 19 v
27 1a w
28 1b x
29 1c y
30 1d z
Dec Hex Description
31 1f 1
32 20 2
33 21 3
34 22 4
35 23 5
36 24 6
37 25 7
38 26 8
39 27 9
40 28 Enter
41 29 Escape
42 2a Backspace
43 2b Tab
44 2c
45 2d -
46 2e =
47 2f [
48 30 ]
49 31 Unknown
50 32 Right \
51 33 ;
52 34 '
53 35 ~
54 36 ,
55 37 .
56 38 /
57 39 Caps Lock
Dec Hex Description
58 3a F1
59 3b F2
60 3c F3
61 3d F4
62 3e F5
63 3f F6
64 40 F7
65 41 F8
66 42 F9
67 43 F10
68 44 F11
69 45 F12
70 46 Print screen
71 47 Scroll lock
72 48 Pause / Break
73 49 Insert
74 4a Home
75 4b Page Up
76 4c Delete
77 4d End
78 4e Page Down
79 4f Arrow Right
80 50 Arrow Left
81 51 Arrow Down
82 52 Arrow Up
Dec Hex Description
83 53 Numlock
84 54 Numpad /
85 55 Numpad *
86 56 Numpad -
87 57 Numpad +
88 58 Numpad Enter
89 59 Numpad 1
90 5a Numpad 2
91 5b Numpad 3
92 5c Numpad 4
93 5d Numpad 5
94 5e Numpad 6
95 5f Numpad 7
96 60 Numpad 8
97 61 Numpad 9
98 62 Numpad 0
99 63 Numpad .
100 64 Left \
101 65 Menu key