summaryrefslogtreecommitdiff
path: root/sys/man/8/kbdfs
blob: b7b1f91b8e3c953fd90ba1f2ba8a1e003542965d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
.TH KBDFS 8
.SH NAME
kbdfs, console \- keyboard and console filesystem
.SH SYNOPSIS
.B aux/kbdfs
[
.B -Dd
] [
.B -s
.I srv
] [
.B -m
.I mntpnt
] [
.I consfile
]
.nf

.B mount -b /srv/cons /dev
.B /dev/cons
.B /dev/consctl
.B /dev/kbd
.B /dev/kbdin
.B /dev/kbin
.B /dev/kbmap
.fi
.PP
.B console
[
.I cmd
.I args...
]
.SH DESCRIPTION
.PP
Started on 
.IR boot (8),
.IR kbdfs
translates raw keyboard scancodes from 
.B /dev/scancode
(see
.IR kbd (3))
and its
.BR kbin
and
.BR kbdin
file and optionally reads console input from
.I consfile
to provide initial keyboard and console input.
.PP
It serves a one-level directory containing the files
.BR cons,
.BR consctl,
.BR kbd,
.BR kbdin,
.BR kbin
and
.BR kbmap.
.PP
The
.B -D
flag enables a debug trace of
.I 9p
messages and
.B -d
prevents 
.IR kbdfs
from making its memory private.
.PP
The
.B -s
option causes
.IR kbdfs
to post its channel on
.B /srv/\fIsrv\fP.
On system startup,
.IR boot (8)
sets this to
.B cons.
With the
.B -m
option,
.IR kbdfs
mounts itself on
.I mntpnt
(see
.IR bind (2)),
otherwise on
.B /dev
(the default).
.PP
The
.B console
command executes
.I cmd
(defaults to the system shell)
under its own
.I kbdfs
instance providing a serial console if
.B $console
environment variable is set.
.SS Console
.PP
Reading the
.BR cons
file returns characters typed on the console.  Normally, characters
are buffered to enable erase and kill processing.  
A control-U, 
.LR ^U ,
typed at the keyboard
.I erases
the current input line (removes all
characters from the buffer of characters not yet read via cons), and a
backspace
.I erases
the previous non-kill, non-erase character from the
input buffer.
The combination control-W,
.LR ^W ,
deletes the input last word.
Killing and erasing only delete characters back to, but
not including, the last newline.  Characters typed at the keyboard
actually produce 16-bit runes (see
.IR utf (6)),
but the runes are translated into the variable-length
.SM UTF
encoding (see
.IR utf (6))
before putting them into the buffer. A
.IR read (2)
of a length greater than zero causes the process to wait until a newline
or a
.LR ^D
ends the buffer, and then returns as much of the buffer as the
argument to read allows, but only up to one complete line.  A
terminating
.LR ^D
is not put into the buffer.  If part of the line remains, the next
read will return bytes from that remainder and not part of any new
line that has been typed since.
.PP
If the string
.B rawon
has been written to the
.BR consctl
file and the file
is still open,
.BR cons
is in
.IR "raw mode" :
characters are not echoed as they are typed,
backspace,
.L ^U,
.L ^W
and
.L ^D
are not treated specially, and characters are
available to read as soon as they are typed.  Ordinary mode is
reentered when
.B rawoff
is written to
.BR consctl
or this file is closed.
.PP
A write (see 
.IR read (2))
to
.BR cons
causes the characters to be printed on the console screen.
.PP
When a
.I consfile
is passed to
.IR kbdfs (8)
as its last argument, it reads and processes the
characters from that file and forwards them to the
.BR cons
file with the same text processing applied as on keyboard input.
This is used to provide a serial console when
.B $console
environment variable is set. (see
.IR plan9.ini (8)).
.PP
Holding
.LR Ctrl
+
.LR Alt
and then pressing the
.LR Del
key will
trigger a reboot of the terminal.
To forward this sequence downstream,
.LR Shift
+
.LR Ctrl
+
.LR Alt
and then pressing
.LR Del
will cause to send a
.LR Shift
up before the
.LR Del
key.
This is useful for programs like
.IR vnc (1)
and
.IR vmx (1).
.SS Keyboard
A read on the
.BR kbd
file returns the character
.B k,
.B K
or
.B c
followed by a null terminated, variable-length,
.SM UTF
encoded string. The
.B k
message is sent when a key is pressed down
and
.B K
when a key is released. The following string contains all the keycodes
of the keys that are currently pressed down in unshifted form. 
This includes all keys that have a keyboard mapping and modifier keys.
The string following the
.B c
message contains the single character that would have been returned
on the
.BR cons
file instead. The
.B c
message will be resent at the keyboard repeat rate.
A single
.IR read (2)
can return multiple concatenated messages at once (delimited by the null byte)
or block when there are no messages queued. Opening the
.BR kbd
file disables input processing on the
.BR cons
file until it is closed again.
.PP
.B K,
.B k
and
.B c
messages can be written to
.BR kbdin
and will forwarded to the reader of
.BR cons
or
.BR kbd.
Writing a
.B r
or
.B R
message followed by a
.SM UTF
encoded rune will simulate the press or
release of that particular rune.
.PP
Raw scancodes can be written to the
.BR kbin
file for external keyboard input (used for USB keyboards).
.SS "Keyboard map"
PS/2 keyboards generate one and two byte scancodes sequences
which give keyboard events relative to physical key location.
These codes are then translated to Unicode runes using a series
of tables hereafter referred to as layers. The true mapping
of scancodes is locale and potentially device specific.
.PP
The PS/2 interface presents two physical layers, switched on if
the input scancode is one or two bytes. This second "escaped" layer
is typically generated for keys like
.LR Home
and
.LR Ins .
.IR Kbdfs
additionally maintains eight more virtual layers that are switched on
.LR Shift ,
.LR Ctl ,
.LR AltGr ,
and
.LR Mod4
modifier key state. Not all permutations of these modifiers are represented
as layers, the exhaustive list is as follows:
.TP \w'shiftaltgr\ \ \ \ \ 'u
.I none
Key
.PD 0
.TP
.I shift
Shift + Key
.TP
.I esc
Escaped Key
.TP
.I altgr
AltGr + Key
.TP
.I ctl
Ctl + Key
.TP
.I ctlesc
Ctl + Escaped Key
.TP
.I shiftesc
Shift + Escaped Key
.TP
.I shiftaltgr
Shift + AltGr + Key
.TP
.I mod4
Mod4 + Key
.TP
.I altgrmod4
AltGr + Mod4 + Key
.PD
.PP
These layers can be accessed with the
.BR kbmap
file. A map entry is a line containing
three whitespace separated fields:
the layer name, the scancode, and the resulting
Unicode value. A layer may also historically
be addressed by its numeric index in the above list.
A Unicode value of zero indicates to drop that particular
input.
.PP
Reads return the current contents of the map.
Each map entry has its fields padded to 11
characters.
.PP
Writes accept new map entries.
Numeric values are taken to be decimal
unless they start with
.B 0x
(hexadecimal) or
.B 0
(octal).
The Unicode character can also be represented as
.BI ' x
where
.I x
gives the UTF-8 representation of the character
(see
.IR utf (6)),
or as 
.BI ^ X
to represent a control character.
.PP
Opening
.BR kbmap
with
.BR OTRUNC
resets the map back to the preloaded
ascii defaults.
.SH "SEE ALSO"
.IR cons (3),
.IR keyboard (6),
.IR utf (6),
.IR kbd (3),
.IR plan9.ini (8)
.SH FILES
.B /sys/lib/kbmap/*
.SH SOURCE
.B /sys/src/cmd/aux/kbdfs
.br
.B /rc/bin/console
.SH HISTORY
.I Kbdfs
first appeared in 9front (May, 2011).