1kb(7M)                          STREAMS Modules                         kb(7M)
2
3
4

NAME

6       kb - keyboard STREAMS module
7

SYNOPSIS

9       #include <sys/types.h>
10
11
12       #include <sys/stream.h>
13
14
15       #include <sys/stropts.h>
16
17
18       #include <sys/vuid_event.h>
19
20
21       #include <sys/kbio.h>
22
23
24       #include <sys/kbd.h>
25
26
27       ioctl(fd, I_PUSH, "kb");
28
29

DESCRIPTION

31       The  kb  STREAMS  module processes byte streams generated by a keyboard
32       attached to a CPU serial port. Definitions for altering keyboard trans‐
33       lation   and   reading  events  from  the  keyboard  are  contained  in
34       <sys/kbio.h> and <sys/kbd.h>.
35
36
37       The kb STREAMS module utilizes a set of keyboard  tables  to  recognize
38       which  keys  have been typed. Each translation table is an array of 128
39       16-bit words (unsigned shorts). If a table entry is  less  than  0x100,
40       the entry is treated as an ISO 8859/1 character. Higher values indicate
41       special characters that invoke more complicated actions.
42
43   Keyboard Translation Mode
44       The keyboard can be in one of the following translation modes:
45
46       TR_NONE              Keyboard translation is turned off and up/down key
47                            codes are reported.
48
49
50       TR_ASCII             ISO 8859/1 codes are reported.
51
52
53       TR_EVENT             firm_events are reported.
54
55
56       TR_UNTRANS_EVENT     firm_events  containing unencoded keystation codes
57                            are reported for all input events within the  win‐
58                            dow system.
59
60
61   Keyboard Translation-Table Entries
62       All instances of the kb module share seven translation tables that con‐
63       vert raw keystation codes to event values. The tables are:
64
65       Unshifted     Used when a key is depressed and no shifts are in effect.
66
67
68       Shifted       Used when a key is depressed and  a  Shift  key  is  held
69                     down.
70
71
72       Caps Lock     Used when a key is depressed and Caps Lock is in effect.
73
74
75       Alt Graph     Used  when  a  key  is depressed and the Alt Graph key is
76                     held down.
77
78
79       Num Lock      Used when a key is depressed and Num Lock is in effect.
80
81
82       Controlled    Used when a key is depressed and the Control key is  held
83                     down. (Regardless of whether a Shift key or the Alt Graph
84                     is being held down, or whether Caps Lock or Num  Lock  is
85                     in effect).
86
87
88       Key Up        Used when a key is released.
89
90
91
92       Each  key on the keyboard has a key station code that represents a num‐
93       ber from 0 to 127. The number is used as an index into the  translation
94       table  that  is  currently in effect. If the corresponding entry in the
95       translation table is a value from 0 to 255, the value is treated as  an
96       ISO  8859/1  character, and the character is the result of the transla‐
97       tion.
98
99
100       If the entry in the translation table is higher than 255, it is a  spe‐
101       cial  entry. Special entry values are classified according to the value
102       of the high-order bits. The high-order value for each class is  defined
103       as a constant, as shown below. When added to the constant, the value of
104       the low-order bits distinguish between keys within each class:
105
106       SHIFTKEYS 0x100     A shift key. The value of the particular shift  key
107                           is added to determine which shift mask to apply:
108
109                           CAPSLOCK 0       Caps Lock key.
110
111
112                           SHIFTLOCK 1      "Shift Lock" key.
113
114
115                           LEFTSHIFT 2      Left-hand Shift key.
116
117
118                           RIGHTSHIFT 3     Right-hand Shift key.
119
120
121                           LEFTCTRL 4       Left-hand (or only) Control key.
122
123
124                           RIGHTCTRL 5      Right-hand Control key.
125
126
127                           ALTGRAPH 9        Alt Graph key.
128
129
130                           ALT 10            Alternate or Alt key.
131
132
133                           NUMLOCK 11        Num Lock key.
134
135
136
137       BUCKYBITS 0x200     Used  to  toggle  mode-key-up/down  status  without
138                           altering the value of an  accompanying  ISO  8859/1
139                           character.  The actual bit-position value, minus 7,
140                           is added.
141
142                           METABIT 0       The Meta key was pressed along with
143                                           the  key.  This  is  the only user-
144                                           accessible bucky bit. It is ORed in
145                                           as  the 0x80 bit; since this bit is
146                                           a legitimate bit  in  a  character,
147                                           the   only   way   to   distinguish
148                                           between,  for  example,   0xA0   as
149                                           META+0x20  and  0xA0  as  an  8-bit
150                                           character is to watch for META  key
151                                           up  and  META  key  down events and
152                                           keep track of whether the META  key
153                                           was down.
154
155
156                           SYSTEMBIT 1     The System key was pressed. This is
157                                           a place holder  to  indicate  which
158                                           key is the system-abort key.
159
160
161
162       FUNNY 0x300         Performs  various  functions depending on the value
163                           of the low 4 bits:
164
165                           NOP 0x300           Does nothing.
166
167
168                           OOPS 0x301          Exists, but is undefined.
169
170
171                           HOLE 0x302          There is no key in  this  posi‐
172                                               tion  on  the keyboard, and the
173                                               position-code  should  not   be
174                                               used.
175
176
177                           RESET 0x306         Keyboard reset.
178
179
180                           ERROR 0x307         The keyboard driver detected an
181                                               internal error.
182
183
184                           IDLE 0x308          The keyboard is idle  (no  keys
185                                               down).
186
187
188                           COMPOSE 0x309       The  COMPOSE  key; the next two
189                                               keys  should  comprise  a  two-
190                                               character COMPOSE key sequence.
191
192
193                           NONL 0x30A          Used  only  in the Num Lock ta‐
194                                               ble; indicates that this key is
195                                               not  affected  by  the Num Lock
196                                               state, so that the  translation
197                                               table  to use to translate this
198                                               key  should  be  the  one  that
199                                               would  have  been  used had Num
200                                               Lock not been in effect.
201
202
203                           0x30B — 0x30F       Reserved for  non-parameterized
204                                               functions.
205
206
207
208       FA_CLASS 0x400      A  floating  accent or "dead key." When this key is
209                           pressed, the next key generates  an  event  for  an
210                           accented  character;  for example, "floating accent
211                           grave" followed by the "a" key generates  an  event
212                           with  the  ISO  8859/1  code  for the "a with grave
213                           accent"  character.  The  low-order  bits  indicate
214                           which  accent; the codes for the individual "float‐
215                           ing accents" are as follows:
216
217                           FA_UMLAUT 0x400      umlaut
218
219
220                           FA_CFLEX 0x401       circumflex
221
222
223                           FA_TILDE 0x402       tilde
224
225
226                           FA_CEDILLA 0x403     cedilla
227
228
229                           FA_ACUTE 0x404       acute accent
230
231
232                           FA_GRAVE 0x405       grave accent
233
234
235
236       STRING 0x500        The low-order bits index a table of strings. When a
237                           key  with  a STRING entry is depressed, the charac‐
238                           ters in the null-terminated string for that key are
239                           sent, character-by-character. The maximum length is
240                           defined as:
241
242                           KTAB_STRLEN     10
243
244                           Individual string numbers are defined as:
245
246                           HOMEARROW      0x00
247
248
249                           UPARROW        0x01
250
251
252                           DOWNARROW      0x02
253
254
255                           LEFTARROW      0x03
256
257
258                           RIGHTARROW     0x04
259
260                           String numbers 0x05 — 0x0F are available for custom
261                           entries.
262
263
264       FUNCKEYS 0x600      There  are  64 keys reserved for function keys. The
265                           actual    positions    are    usually    on     the
266                           left/right/top/bottom of the keyboard.
267
268                           The  next-to-lowest  4  bits  indicate the group of
269                           function keys:
270
271                           LEFTFUNC          0x600
272
273
274                           RIGHTFUNC         0x610
275
276
277                           TOPFUNC 0x610     0x610
278
279
280                           BOTTOMFUNC        0x630
281
282                           The low 4 bits indicate  the  function  key  number
283                           within the group:
284
285                           LF(n)     (LEFTFUNC+(n)-1)
286
287
288                           RF(n)     (RIGHTFUNC+(n)-1)
289
290
291                           TF(n)     (TOPFUNC+(n)-1)
292
293
294                           BF(n)     (BOTTOMFUNC+(n)-1)
295
296
297
298       PADKEYS 0x700     A  "numeric  keypad key." These entries should appear
299                         only in the Num Lock translation table; when Num Lock
300                         is  in  effect,  these  events  will  be generated by
301                         pressing keys on the right-hand keypad. The low-order
302                         bits indicate which key. The codes for the individual
303                         keys are:
304
305                         PADEQUAL 0x700     "=" key
306
307
308                         PADSLASH 0x701     "/" key
309
310
311                         PADSTAR 0x702      "*" key
312
313
314                         PADMINUS 0x703     "-" key
315
316
317                         PADSEP 0x704       "," key
318
319
320                         PAD7 0x705         "7" key
321
322
323                         PAD8 0x706         "8" key
324
325
326                         PAD9 0x707         "9" key
327
328
329                         PADPLUS 0x708      "+" key
330
331
332                         PAD4 0x709         "4" key
333
334
335                         PAD5 0x70A         "5" key
336
337
338                         PAD6 0x70B         "6" key
339
340
341                         PAD1 0x70C         "1" key
342
343
344                         PAD2 0x70D         "2" key
345
346
347                         PAD3 0x70E         "3" key
348
349
350                         PAD0 0x70F         "0" key
351
352
353                         PADDOT 0x710       "." key
354
355
356                         PADENTER 0x711     "Enter" key
357
358
359
360
361       When a function key is pressed in TR_ASCII mode, the  following  escape
362       sequence is sent:
363
364
365       ESC[0....9z
366
367
368       where  ESC is a single escape character and "0...9" indicates the deci‐
369       mal representation of the function-key value. For example, function key
370       R1 sends the sequence:
371
372
373       ESC[208z
374
375
376       because  the  decimal value of RF(1) is 208. In TR_EVENT mode, if there
377       is a VUID event code for the function key in question,  an  event  with
378       that  event  code  is  generated;  otherwise, individual events for the
379       characters of the escape sequence are generated.
380
381   Keyboard Compatibility Mode
382       When started, the kb STREAMS module is in the compatibility mode.  When
383       the keyboard is in the TR_EVENT translation mode, ISO 8859/1 characters
384       from the upper half of the character set (that is, characters with  the
385       eighth  bit  set) , are presented as events with codes in the ISO_FIRST
386       range (as defined in <<sys/vuid_event.h>>). For backwards compatibility
387       with older versions of the keyboard driver, the event code is ISO_FIRST
388       plus the character value. When compatibility mode is  turned  off,  ISO
389       8859/1 characters are presented as events with codes equal to the char‐
390       acter code.
391

DESCRIPTION

393       The following ioctl() requests set and retrieve the current translation
394       mode of a keyboard:
395
396       KIOCTRANS      Pointer  to  an  int. The translation mode is set to the
397                      value in the int pointed to by the argument.
398
399
400       KIOCGTRANS     Pointer to an  int.  The  current  translation  mode  is
401                      stored in the int pointed to by the argument.
402
403
404
405       ioctl()  requests for changing and retrieving entries from the keyboard
406       translation table use the kiockeymap structure:
407
408         struct kiockeymap {
409         int  kio_tablemask; /* Translation table (one of: 0, CAPSMASK,
410                         * SHIFTMASK, CTRLMASK, UPMASK,
411                         * ALTGRAPHMASK, NUMLOCKMASK)
412                         */
413         #define KIOCABORT1 -1      /* Special "mask": abort1 keystation */
414         #define KIOCABORT2 -2      /* Special "mask": abort2 keystation */
415              uchar_t kio_station; /* Physical keyboard key station (0-127) */
416              ushort_t kio_entry;    /* Translation table station's entry */
417              char kio_string[10]; /* Value for STRING entries-null terminated */
418         };
419
420
421       KIOCSKEY     Pointer to a kiockeymap structure. The  translation  table
422                    entry  referred  to  by  the  values  in that structure is
423                    changed. The kio_tablemask request specifies which of  the
424                    following translation tables contains the entry to be mod‐
425                    ified:
426
427                    UPMASK 0x0080
428
429                        "Key Up" translation table.
430
431
432                    NUMLOCKMASK 0x0800
433
434                        "Num Lock" translation table.
435
436
437                    CTRLMASK 0x0030
438
439                        "Controlled" translation table.
440
441
442                    ALTGRAPHMASK 0x0200
443
444                        "Alt Graph" translation table.
445
446
447                    SHIFTMASK 0x000E
448
449                        "Shifted" translation table.
450
451
452                    CAPSMASK 0x0001
453
454                        "Caps Lock" translation table.
455
456
457                    (No shift keys pressed or locked)
458
459                        "Unshifted" translation table.
460
461
462
463
464       The kio_station request specifies the keystation code for the entry  to
465       be modified. The value of kio_entry is stored in the entry in question.
466       If kio_entry is between STRING and STRING+15, the string  contained  in
467       kio_string  is  copied to the appropriate string table entry. This call
468       may return EINVAL if there are invalid arguments.
469
470
471       Special values of kio_tablemask can affect the two step "break  to  the
472       PROM  monitor"  sequence.  The  usual  sequence  is  L1-a  or Stop-. If
473       kio_tablemask is KIOCABORT1, then the value of kio_station is set to be
474       the  first  keystation in the sequence. If kio_tablemask, is KIOCABORT2
475       then the value of kio_station is set to be the second keystation in the
476       sequence.  An  attempt  to  change  the  "break  to  the  PROM monitor"
477       sequence without having  superuser  permission  results  in  an   EPERM
478       error.
479
480       KIOCGKEY     The  argument  is a pointer to a kiockeymap structure. The
481                    current value of  the  keyboard  translation  table  entry
482                    specified  by  kio_tablemask  and kio_station is stored in
483                    the structure pointed to by the argument.  This  call  may
484                    return EINVAL if there are invalid arguments.
485
486
487       KIOCTYPE     The argument is a pointer to an int. A code indicating the
488                    type of the keyboard is stored in the int  pointed  to  by
489                    the argument:
490
491                    KB_SUN3       Sun Type 3 keyboard
492
493
494                    KB_SUN4       Sun  Type  4  or  5 keyboard, or non-USB Sun
495                                  Type 6 keyboard
496
497
498                    KB_USB        USB standard  HID  keyboard,  including  Sun
499                                  Type 6 USB keyboards
500
501
502                    KB_ASCII      ASCII terminal masquerading as keyboard
503
504
505                    KB_PC         Type 101 PC keyboard
506
507
508                    KB_DEFAULT     Stored  in  the int pointed to by the argu‐
509                                  ment if the keyboard  type  is  unknown.  In
510                                  case  of  error,  -1  is  stored  in the int
511                                  pointed to by the argument.
512
513
514
515       KIOCLAYOUT     The argument is a pointer to an int. On  a  Sun  Type  4
516                      keyboard,  the  layout  code specified by the keyboard's
517                      DIP switches is stored in the  int  pointed  to  by  the
518                      argument.
519
520
521       KIOCCMD        The  argument is a pointer to an int. The command speci‐
522                      fied by the value of the int pointed to by the  argument
523                      is  sent  to the keyboard. The commands that can be sent
524                      are:
525
526                      Commands to the Sun Type 3 and Sun Type 4 keyboards:
527
528                      KBD_CMD_RESET       Reset keyboard as if power-up.
529
530
531                      KBD_CMD_BELL        Turn on the bell.
532
533
534                      KBD_CMD_NOBELL      Turn off the bell.
535
536
537                      KBD_CMD_CLICK       Turn on the click annunciator.
538
539
540                      KBD_CMD_NOCLICK     Turn off the click annunciator.
541
542                      Commands to the Sun Type 4 keyboard:
543
544                      KBD_CMD_SETLED        Set keyboard LEDs.
545
546
547                      KBD_CMD_GETLAYOUT     Request  that  keyboard   indicate
548                                            layout.
549
550
551
552
553       Inappropriate commands for particular keyboard types are ignored. Since
554       there is no reliable way to get the state of the bell or click (because
555       the  keyboard  cannot  be  queried and a process could do writes to the
556       appropriate serial driver —  circumventing  this  ioctl()  request)  an
557       equivalent ioctl() to query its state is not provided.
558
559       KIOCSLED     The  argument  is  a pointer to an char. On the Sun Type 4
560                    keyboard, the LEDs are set to the value specified in  that
561                    char. The values for the four LEDs are:
562
563                    LED_CAPS_LOCK       "Caps Lock" light.
564
565
566                    LED_COMPOSE         "Compose" light.
567
568
569                    LED_SCROLL_LOCK     "Scroll Lock" light.
570
571
572                    LED_NUM_LOCK        "Num Lock" light.
573
574                    On some Japanese layouts, the value for the fifth  LED is:
575
576                    LED_KANA     "Kana" light.
577
578
579
580       KIOCGLED        Pointer  to  a  char.  The current state of the LEDs is
581                       stored in the char pointed to by the argument.
582
583
584       KIOCSCOMPAT     Pointer to an int. "Compatibility mode" is turned on if
585                       the  int has a value of 1, and is turned off if the int
586                       has a value of 0.
587
588
589       KIOCGCOMPAT     Pointer to an int. The current state of  "compatibility
590                       mode" is stored in the int pointed to by the argument.
591
592
593
594       The following ioctl() request allows the default effect of the keyboard
595       abort sequence to be changed.
596
597       KIOCSKABORTEN     Pointer to an int. The keyboard abort sequence effect
598                         (typically  L1-A  or  Stop-A on the keyboard on SPARC
599                         systems, F1-A on x86 systems, and BREAK on the serial
600                         console  device) is enabled if the int has a value of
601                         KIOCABORTENABLE(1). If  the  value  is  KIOCABORTDIS‐
602                         ABLE(0)  , the keyboard abort sequence effect is dis‐
603                         abled. If the  value  is  KIOCABORTALTERNATE(2),  the
604                         Alternate  Break sequence is in effect and is defined
605                         by  the  serial  console  drivers  zs(7D)se(7D)   and
606                         asy(7D).  Any  other  value of the parameter for this
607                         ioctl() is treated as  enable.  The  Alternate  Break
608                         sequence  is applicable to the serial console devices
609                         only.
610
611                         Due to a risk of incorrect  sequence  interpretation,
612                         SLIP and certain other binary protocols should not be
613                         run over the serial console port when Alternate Break
614                         sequence  is in effect. Although PPP is a binary pro‐
615                         tocol, it is able to avoid these sequences using  the
616                         ACCM feature in RFC 1662. For Solaris PPP 4.0, you do
617                         this  by   adding   the   following   line   to   the
618                         /etc/ppp/options  file  (or other configuration files
619                         used for the connection; see pppd(1M) for details):
620
621                           asyncmap  0x00002000
622
623                         SLIP has no comparable capability, and  must  not  be
624                         used if the Alternate Break sequence is in use.
625
626                         This  ioctl() will be active and retain state even if
627                         there is no physical  keyboard  in  the  system.  The
628                         default  effect  (enable) causes the operating system
629                         to suspend and enter the kernel debugger (if present)
630                         or  the  system  prom  (on most systems with OpenBoot
631                         proms). The default effect is enabled  on  most  sys‐
632                         tems, but may be different on server systems with key
633                         switches in the 'secure' position. On these  systems,
634                         the  effect is always disabled when the key switch is
635                         in the 'secure' position. This  ioctl()returns  EPERM
636                         if the caller is not the superuser.
637
638
639
640       These  ioctl() requests are supported for compatibility with the system
641       keyboard device /dev/kbd.
642
643       KIOCSDIRECT     Has no effect.
644
645
646       KIOCGDIRECT     Always returns 1.
647
648
649
650       The following ioctl() requests are used to set  and  get  the  keyboard
651       autorepeat delay and rate.
652
653       KIOCSRPTDELAY     This argument is a pointer to an int, which is the kb
654                         autorepeat delay, unit in millisecond.
655
656
657       KIOCGRPTDELAY     This argument is a pointer to  an  int.  The  current
658                         auto  repeat  delay  setting is stored in the integer
659                         pointed by the argument, unit in millisecond.
660
661
662       KIOCSRPTRATE      This argument is a pointer to an int, which is the kb
663                         autorepeat rate, unit in millisecond.
664
665
666       KIOCGRPTRATE      This  argument  is  a  pointer to an int. The current
667                         auto repeat rate setting is  stored  in  the  integer
668                         pointed by the argument, unit in millisecond.
669
670

ATTRIBUTES

672       See attributes(5) for descriptions of the following attributes:
673
674
675
676
677       ┌─────────────────────────────┬─────────────────────────────┐
678ATTRIBUTE TYPE               ATTRIBUTE VALUE              
679       ├─────────────────────────────┼─────────────────────────────┤
680       │Interface Stability          │Stable                       │
681       └─────────────────────────────┴─────────────────────────────┘
682

SEE ALSO

684       kbd(1),  loadkeys(1),  kadb(1M), pppd(1M), keytables(4), attributes(5),
685       zs(7D), se(7D), asy(7D), virtualkm(7D), termio(7I), usbkbm(7M)
686

NOTES

688       Many keyboards released after Sun Type 4  keyboard  also  report  them‐
689       selves  as Sun Type 4 keyboards.
690
691
692
693SunOS 5.11                        26 Feb 2004                           kb(7M)
Impressum