xref: /illumos-gate/usr/src/uts/common/sys/kbd.h (revision adc2b73d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5e4603304Sqz150045  * Common Development and Distribution License (the "License").
6e4603304Sqz150045  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22e4603304Sqz150045  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23e4603304Sqz150045  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_KBD_H
277c478bd9Sstevel@tonic-gate #define	_SYS_KBD_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * Following #defines are related to the older keyboards which
357c478bd9Sstevel@tonic-gate  * are no longer supported by kb module.  The #defines ane left
367c478bd9Sstevel@tonic-gate  * for older programs to still compile.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate #define	KB_KLUNK	0x00		/* Micro Switch 103SD32-2 */
397c478bd9Sstevel@tonic-gate #define	KB_VT100	0x01		/* Keytronics VT100 compatible */
407c478bd9Sstevel@tonic-gate #define	KB_SUN2		0x02		/* Sun-2 custom keyboard */
417c478bd9Sstevel@tonic-gate #define	KB_VT220	0x81		/* Emulation VT220 */
427c478bd9Sstevel@tonic-gate #define	KB_VT220I	0x82		/* International VT220 Emulation */
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #define	NOTPRESENT	0xFF		/* Keyboard is not plugged in */
457c478bd9Sstevel@tonic-gate #define	KBD_CMD_LED1	0x04		/* Turn on LED 1 for Sun-2 */
467c478bd9Sstevel@tonic-gate #define	KBD_CMD_NOLED1	0x05		/* Turn off LED 1 for Sun-2 */
477c478bd9Sstevel@tonic-gate #define	KBD_CMD_LED2	0x06		/* Turn on LED 2 for Sun-2 */
487c478bd9Sstevel@tonic-gate #define	KBD_CMD_NOLED2	0x07		/* Turn off LED 2 for Sun-2 */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #define	CTLSMASK	0x0100		/* Set if ^S was last keyed of ^S, ^Q */
517c478bd9Sstevel@tonic-gate 					/* determines which NOSCROLL sends. */
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #define	NOSCROLL	0x303	/* This key alternately sends ^S or ^Q */
547c478bd9Sstevel@tonic-gate #define	CTRLS		0x304	/* This sends ^S and lets NOSCROLL know */
557c478bd9Sstevel@tonic-gate #define	CTRLQ		0x305	/* This sends ^Q and lets NOSCROLL know */
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate  * Following are the only keyboard types supported by kb module.
607c478bd9Sstevel@tonic-gate  * (Type 5, Hobo, US101A are also supported but they report
617c478bd9Sstevel@tonic-gate  * themselves as Type 4 keyboard with a different layout id.)
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate #define	KB_SUN3		3		/* Type 3 Sun keyboard */
647c478bd9Sstevel@tonic-gate #define	KB_SUN4		4		/* Type 4 Sun keyboard */
657c478bd9Sstevel@tonic-gate #define	KB_USB		6		/* USB keyboard */
667c478bd9Sstevel@tonic-gate #define	KB_PC		101		/* Type 101 AT keyboard */
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #define	KB_ASCII	0x0F		/* Ascii terminal masquerading as kbd */
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate  * This structure is used to enumerate the supported keyboard types.
727c478bd9Sstevel@tonic-gate  * The array of these is terminated by an entry with a NULL table entry.
737c478bd9Sstevel@tonic-gate  * The first entry is used if none match.
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate struct keyboards {
767c478bd9Sstevel@tonic-gate 	int		id;	/* Keyboard type, per KIOCTYPE */
777c478bd9Sstevel@tonic-gate 	struct keyboard	*table;	/* Keyboard table to use. */
787c478bd9Sstevel@tonic-gate };
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate /*
817c478bd9Sstevel@tonic-gate  * Various special characters that might show up on the port
827c478bd9Sstevel@tonic-gate  */
837c478bd9Sstevel@tonic-gate #define	IDLEKEY		0x7F		/* Keyboard is idle; no keys down */
847c478bd9Sstevel@tonic-gate #define	ERRORKEY	0x7E		/* Keyboard detected an error */
857c478bd9Sstevel@tonic-gate #define	RESETKEY	0xFF		/* Keyboard was just reset */
867c478bd9Sstevel@tonic-gate #define	LAYOUTKEY	0xFE		/* Keyboard layout byte follows */
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #define	PRESSED		0x00		/* 0x80 bit off: key was pressed */
897c478bd9Sstevel@tonic-gate #define	RELEASED	0x80		/* 0x80 bit on : key was released */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  * Commands to the Sun-3 keyboard.
937c478bd9Sstevel@tonic-gate  */
947c478bd9Sstevel@tonic-gate #define	KBD_CMD_RESET		0x01	/* Reset keyboard as if power-up */
957c478bd9Sstevel@tonic-gate #define	KBD_CMD_BELL		0x02	/* Turn on the bell */
967c478bd9Sstevel@tonic-gate #define	KBD_CMD_NOBELL		0x03	/* Turn off the bell */
977c478bd9Sstevel@tonic-gate #define	KBD_CMD_CLICK		0x0A	/* Turn on the click annunciator */
987c478bd9Sstevel@tonic-gate #define	KBD_CMD_NOCLICK		0x0B	/* Turn off the click annunciator */
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate  * Commands to the Type 4 keyboard, in addition to those above.
1027c478bd9Sstevel@tonic-gate  */
1037c478bd9Sstevel@tonic-gate #define	KBD_CMD_AUTOTEST	0x0C	/* Initiate test sequence */
1047c478bd9Sstevel@tonic-gate #define	KBD_CMD_SETLED		0x0E	/* Set keyboard LED's */
1057c478bd9Sstevel@tonic-gate #define	KBD_CMD_GETLAYOUT	0x0F	/* Request that keyboard indicate */
1067c478bd9Sstevel@tonic-gate 					/* layout */
1077c478bd9Sstevel@tonic-gate /*
1087c478bd9Sstevel@tonic-gate  * Type 4 keyboard LED masks (used to set LED's)
1097c478bd9Sstevel@tonic-gate  */
1107c478bd9Sstevel@tonic-gate #define	LED_NUM_LOCK	0x1
1117c478bd9Sstevel@tonic-gate #define	LED_COMPOSE	0x2
1127c478bd9Sstevel@tonic-gate #define	LED_SCROLL_LOCK 0x4
1137c478bd9Sstevel@tonic-gate #define	LED_CAPS_LOCK	0x8
1147c478bd9Sstevel@tonic-gate #define	LED_KANA	0x10		/* Valid only on Japanese layout */
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate  * Software related definitions
1187c478bd9Sstevel@tonic-gate  */
1197c478bd9Sstevel@tonic-gate /*
1207c478bd9Sstevel@tonic-gate  * These are the states that the keyboard scanner can be in.
1217c478bd9Sstevel@tonic-gate  *
1227c478bd9Sstevel@tonic-gate  * It starts out in NORMAL state.
1237c478bd9Sstevel@tonic-gate  */
1247c478bd9Sstevel@tonic-gate #define	NORMAL		0		/* The usual (ho, hum) */
1257c478bd9Sstevel@tonic-gate #define	ABORT1		1		/* Got KEYABORT1 */
1267c478bd9Sstevel@tonic-gate #define	COMPOSE1	2		/* Got COMPOSE */
1277c478bd9Sstevel@tonic-gate #define	COMPOSE2	3		/* Got COMPOSE plus first key */
1287c478bd9Sstevel@tonic-gate #define	FLTACCENT	4		/* Got floating accent key */
129e4603304Sqz150045 #define	NEWABORT1	5		/* Got NEW KEYABORT1 */
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate /*
1327c478bd9Sstevel@tonic-gate  * Size of ASCII set as used in compose handling.
1337c478bd9Sstevel@tonic-gate  */
1347c478bd9Sstevel@tonic-gate #define	ASCII_SET_SIZE	128
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * These are how you can have your input translated.
1387c478bd9Sstevel@tonic-gate  * TR_EVENT means that each keystroke is sent as a firm event.
1397c478bd9Sstevel@tonic-gate  * TR_UNTRANS_EVENT also sends a firm event for each up / down transition,
1407c478bd9Sstevel@tonic-gate  * but the value is untranslated: the event id is the key station; the
1417c478bd9Sstevel@tonic-gate  * value indicates whether the transition was up or down; the value of the
1427c478bd9Sstevel@tonic-gate  * shift-mask is undefined.
1437c478bd9Sstevel@tonic-gate  */
1447c478bd9Sstevel@tonic-gate #define	TR_NONE		  0
1457c478bd9Sstevel@tonic-gate #define	TR_ASCII	  1
1467c478bd9Sstevel@tonic-gate #define	TR_EVENT	  2
1477c478bd9Sstevel@tonic-gate #define	TR_UNTRANS_EVENT  3
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate /*
1507c478bd9Sstevel@tonic-gate  * These bits can appear in the result of TR_NONE & TR_UNTRANS_EVENT getkey()s.
1517c478bd9Sstevel@tonic-gate  */
1527c478bd9Sstevel@tonic-gate #define	BUILDKEY(key, state)	(key | state)
1537c478bd9Sstevel@tonic-gate #define	STATEOF(key)	((key) & RELEASED)	/* 0 = key down, !=0 = key up */
1547c478bd9Sstevel@tonic-gate #define	KEYOF(key)	((key) & ~RELEASED)	/* The key number that moved */
1557c478bd9Sstevel@tonic-gate #define	NOKEY		(-1)		/* The argument was 0, and no key was */
1567c478bd9Sstevel@tonic-gate 					/* depressed.  They were all elated. */
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate /*
1597c478bd9Sstevel@tonic-gate  * "Bucky" bits.  These are bits for mode keys.	 The META bit is ORed into the
1607c478bd9Sstevel@tonic-gate  * result of TR_ASCII getkey()s, and can be ORed into the result of TR_EVENT
1617c478bd9Sstevel@tonic-gate  * getkey()s for backwards compatibility.
1627c478bd9Sstevel@tonic-gate  * (NOKEY can also appear if no keypress was queued up.)
1637c478bd9Sstevel@tonic-gate  */
1647c478bd9Sstevel@tonic-gate #define	METABIT		0		/* Meta key depressed with key */
1657c478bd9Sstevel@tonic-gate #define	METAMASK	0x000080
1667c478bd9Sstevel@tonic-gate #define	SYSTEMBIT	1		/* Upper left key was down w/key */
1677c478bd9Sstevel@tonic-gate #define	SYSTEMMASK	0x000100
1687c478bd9Sstevel@tonic-gate /* other "bucky" bits can be defined at will.  See "BUCKYBITS" below. */
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate  * This defines the bit positions used within "shiftmask" to
1727c478bd9Sstevel@tonic-gate  * indicate the "pressed" (1) or "released" (0) state of shift keys.
1737c478bd9Sstevel@tonic-gate  * Both the bit numbers, and the aggregate masks, are defined.
1747c478bd9Sstevel@tonic-gate  *
1757c478bd9Sstevel@tonic-gate  * The "UPMASK" is a minor kludge.  Since whether the key is going
1767c478bd9Sstevel@tonic-gate  * up or down determines the translation table (just as the shift
1777c478bd9Sstevel@tonic-gate  * keys' positions do), we OR it with "shiftmask" to get "tempmask",
1787c478bd9Sstevel@tonic-gate  * which is the mask which is actually used to determine the
1797c478bd9Sstevel@tonic-gate  * translation table to use.  Don't reassign 0x0080 for anything
1807c478bd9Sstevel@tonic-gate  * else, or we'll have to shift and such to squeeze in UPMASK,
1817c478bd9Sstevel@tonic-gate  * since it comes in from the hardware as 0x80.
1827c478bd9Sstevel@tonic-gate  */
1837c478bd9Sstevel@tonic-gate #define	CAPSLOCK	0		/* Caps Lock key */
1847c478bd9Sstevel@tonic-gate #define	CAPSMASK	0x0001
1857c478bd9Sstevel@tonic-gate #define	SHIFTLOCK	1		/* Shift Lock key */
1867c478bd9Sstevel@tonic-gate #define	LEFTSHIFT	2		/* Left-hand shift key */
1877c478bd9Sstevel@tonic-gate #define	RIGHTSHIFT	3		/* Right-hand shift key */
1887c478bd9Sstevel@tonic-gate #define	SHIFTMASK	0x000E
1897c478bd9Sstevel@tonic-gate #define	LEFTCTRL	4		/* Left-hand (or only) control key */
1907c478bd9Sstevel@tonic-gate #define	RIGHTCTRL	5		/* Right-hand control key */
1917c478bd9Sstevel@tonic-gate #define	CTRLMASK	0x0030
1927c478bd9Sstevel@tonic-gate /*	META		6		Meta keys */
1937c478bd9Sstevel@tonic-gate /*	META_SHIFT_MASK 0x0040		reserved */
1947c478bd9Sstevel@tonic-gate /*	TOP		7		do not use! */
1957c478bd9Sstevel@tonic-gate /*	TOPMASK		0x0080		UPMASK in keyboard driver */
1967c478bd9Sstevel@tonic-gate /*	CMD		8		reserved */
1977c478bd9Sstevel@tonic-gate /*	CMDMASK		0x0100		reserved */
1987c478bd9Sstevel@tonic-gate #define	ALTGRAPH	9		/* Alt Graph key */
1997c478bd9Sstevel@tonic-gate #define	ALTGRAPHMASK	0x0200
2007c478bd9Sstevel@tonic-gate #define	ALT		10		/* Left (or only) Alt key */
2017c478bd9Sstevel@tonic-gate #define	LEFTALT		10		/* Left Alt key */
2027c478bd9Sstevel@tonic-gate #define	ALTMASK		0x1400
2037c478bd9Sstevel@tonic-gate #define	NUMLOCK		11		/* Num Lock key */
2047c478bd9Sstevel@tonic-gate #define	NUMLOCKMASK	0x0800
2057c478bd9Sstevel@tonic-gate #define	RIGHTALT	12		/* Right Alt key */
2067c478bd9Sstevel@tonic-gate #define	UPMASK		0x0080
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /*
2097c478bd9Sstevel@tonic-gate  * This defines the format of translation tables.
2107c478bd9Sstevel@tonic-gate  *
2117c478bd9Sstevel@tonic-gate  * A translation table is KEYMAP_SIZE "entries", each of which is 2 bytes
2127c478bd9Sstevel@tonic-gate  * (unsigned shorts).  The top 8 bits of each entry are decoded by
2137c478bd9Sstevel@tonic-gate  * a case statement in getkey.c.  If the entry is less than 0x100, it
2147c478bd9Sstevel@tonic-gate  * is sent out as an EUC character (possibly with bucky bits
2157c478bd9Sstevel@tonic-gate  * OR-ed in).  "Special" entries are 0x100 or greater, and
2167c478bd9Sstevel@tonic-gate  * invoke more complicated actions.
2177c478bd9Sstevel@tonic-gate  *
2187c478bd9Sstevel@tonic-gate  * The KEYMAP_SIZE is dependent upon the keyboard type.  For example, the
2197c478bd9Sstevel@tonic-gate  * Sun Type 4/5 keyboards have a KEYMAP_SIZE of 128 where a USB keyboard
2207c478bd9Sstevel@tonic-gate  * has a KEYMAP_SIZE of 255.  Instead of defining a KEYMAP_SIZE per
2217c478bd9Sstevel@tonic-gate  * keyboard type, a keyboard specific module/driver may supply the value
2227c478bd9Sstevel@tonic-gate  * at run time by defining the KEYMAP_SIZE_VARIABLE and filling in the
2237c478bd9Sstevel@tonic-gate  * keyboard struct appropriately.
2247c478bd9Sstevel@tonic-gate  */
2257c478bd9Sstevel@tonic-gate 
226*adc2b73dSToomas Soome typedef unsigned int keymap_entry_t;
2277c478bd9Sstevel@tonic-gate #ifdef KEYMAP_SIZE_VARIABLE
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate #else
2317c478bd9Sstevel@tonic-gate #define	KEYMAP_SIZE	128
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate struct keymap {
234*adc2b73dSToomas Soome 	keymap_entry_t	keymap[KEYMAP_SIZE];	/* maps keycodes to actions */
2357c478bd9Sstevel@tonic-gate };
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate #endif
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate  * This structure is used for "exception" cases for key sequences that
2417c478bd9Sstevel@tonic-gate  * we want to map, that should not be handled by keymap entries (For
2427c478bd9Sstevel@tonic-gate  * example: using Control-Shift-F1 on PC's for the compose key).
2437c478bd9Sstevel@tonic-gate  */
2447c478bd9Sstevel@tonic-gate struct exception_map {
2457c478bd9Sstevel@tonic-gate 	/*
2467c478bd9Sstevel@tonic-gate 	 * these are the modifier keys that we "care" about
2477c478bd9Sstevel@tonic-gate 	 */
2487c478bd9Sstevel@tonic-gate 	unsigned int exc_care;
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate 	/*
2517c478bd9Sstevel@tonic-gate 	 * This is the mask of modifier keys that we want to match
2527c478bd9Sstevel@tonic-gate 	 */
2537c478bd9Sstevel@tonic-gate 	unsigned int exc_mask;
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	/*
2567c478bd9Sstevel@tonic-gate 	 * This is the key that we want to match.
2577c478bd9Sstevel@tonic-gate 	 */
2587c478bd9Sstevel@tonic-gate 	int exc_key;
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate 	/*
2617c478bd9Sstevel@tonic-gate 	 * This is our translated version of the matching sequence.
2627c478bd9Sstevel@tonic-gate 	 */
263*adc2b73dSToomas Soome 	keymap_entry_t exc_entry;
2647c478bd9Sstevel@tonic-gate };
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate /*
2677c478bd9Sstevel@tonic-gate  * A keyboard is defined by its keymaps and what state it resets at idle.
2687c478bd9Sstevel@tonic-gate  *
2697c478bd9Sstevel@tonic-gate  * The masks k_idleshifts and k_idlebuckys are AND-ed with the current
2707c478bd9Sstevel@tonic-gate  * state of  shiftmask	and  buckybits	when a "keyboard idle" code
2717c478bd9Sstevel@tonic-gate  * is received.	 This ensures that where we "think" the shift & bucky
2727c478bd9Sstevel@tonic-gate  * keys are, more accurately reflects where they really are, since the
2737c478bd9Sstevel@tonic-gate  * keyboard knows better than us.  However, some keyboards don't know
2747c478bd9Sstevel@tonic-gate  * about shift states that should be remembered across idles.  Such
2757c478bd9Sstevel@tonic-gate  * shifts are described by k_toggleshifts.  k_toggleshifts are used to
2767c478bd9Sstevel@tonic-gate  * identify such shifts.  A toggle shift state is maintained separately
2777c478bd9Sstevel@tonic-gate  * from the general shift state.  The toggle shift state is OR-ed
2787c478bd9Sstevel@tonic-gate  * with the state general shift state when an idle is received.
2797c478bd9Sstevel@tonic-gate  * k_toggleshifts should not appear in the k_up table.
2807c478bd9Sstevel@tonic-gate  */
2817c478bd9Sstevel@tonic-gate struct keyboard {
2827c478bd9Sstevel@tonic-gate #ifdef KEYMAP_SIZE_VARIABLE
2837c478bd9Sstevel@tonic-gate 	int		k_keymap_size;	/* Number of entries in keymaps */
2847c478bd9Sstevel@tonic-gate 	keymap_entry_t	*k_normal;	/* Unshifted */
2857c478bd9Sstevel@tonic-gate 	keymap_entry_t	*k_shifted;	/* Shifted */
2867c478bd9Sstevel@tonic-gate 	keymap_entry_t	*k_caps;	/* Caps locked */
2877c478bd9Sstevel@tonic-gate 	keymap_entry_t	*k_altgraph;	/* Alt Graph down */
2887c478bd9Sstevel@tonic-gate 	keymap_entry_t	*k_numlock;	/* Num Lock down */
2897c478bd9Sstevel@tonic-gate 	keymap_entry_t	*k_control;	/* Controlled */
2907c478bd9Sstevel@tonic-gate 	keymap_entry_t	*k_up;		/* Key went up */
2917c478bd9Sstevel@tonic-gate #else
2927c478bd9Sstevel@tonic-gate 	struct keymap	*k_normal;	/* Unshifted */
2937c478bd9Sstevel@tonic-gate 	struct keymap	*k_shifted;	/* Shifted */
2947c478bd9Sstevel@tonic-gate 	struct keymap	*k_caps;	/* Caps locked */
2957c478bd9Sstevel@tonic-gate 	struct keymap	*k_altgraph;	/* Alt Graph down */
2967c478bd9Sstevel@tonic-gate 	struct keymap	*k_numlock;	/* Num Lock down */
2977c478bd9Sstevel@tonic-gate 	struct keymap	*k_control;	/* Controlled */
2987c478bd9Sstevel@tonic-gate 	struct keymap	*k_up;		/* Key went up */
2997c478bd9Sstevel@tonic-gate #endif
3007c478bd9Sstevel@tonic-gate 	int		k_idleshifts;	/* Shifts that keep across idle */
3017c478bd9Sstevel@tonic-gate 	int		k_idlebuckys;	/* Bucky bits that keep across idle */
3027c478bd9Sstevel@tonic-gate 	unsigned char	k_abort1;	/* 1st key of abort sequence */
3037c478bd9Sstevel@tonic-gate 	unsigned char	k_abort1a;	/* alternate 1st key */
3047c478bd9Sstevel@tonic-gate 	unsigned char	k_abort2;	/* 2nd key of abort sequence */
3057c478bd9Sstevel@tonic-gate 	int		k_toggleshifts; /* Shifts that toggle on down from */
3067c478bd9Sstevel@tonic-gate 					/* kbd and keep across idle */
3077c478bd9Sstevel@tonic-gate 	struct exception_map *k_except;	/* Oddball cases */
308e4603304Sqz150045 	unsigned char	k_newabort1;	/* 1st key of new abort sequence */
309e4603304Sqz150045 	unsigned char	k_newabort1a;	/* alternate 1st key */
310e4603304Sqz150045 	unsigned char	k_newabort2;	/* 2nd key of new abort sequence */
3117c478bd9Sstevel@tonic-gate };
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate /*
3147c478bd9Sstevel@tonic-gate  * Define the compose sequence structure.  First and second
3157c478bd9Sstevel@tonic-gate  * ASCII chars of 0 indicate the end of the table.
3167c478bd9Sstevel@tonic-gate  */
3177c478bd9Sstevel@tonic-gate struct compose_sequence_t {
3187c478bd9Sstevel@tonic-gate 	unsigned char	first;	/* first ASCII char after COMPOSE key */
3197c478bd9Sstevel@tonic-gate 	unsigned char	second; /* second ASCII char after COMPOSE key */
320*adc2b73dSToomas Soome 	keymap_entry_t	utf8;	/* equivalent UTF-8 code */
3217c478bd9Sstevel@tonic-gate };
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate /*
3247c478bd9Sstevel@tonic-gate  * Define the floating accent sequence structure.
3257c478bd9Sstevel@tonic-gate  */
3267c478bd9Sstevel@tonic-gate struct fltaccent_sequence_t {
327*adc2b73dSToomas Soome 	keymap_entry_t	fa_entry;	/* floating accent keymap entry */
3287c478bd9Sstevel@tonic-gate 	unsigned char	ascii;		/* ASCII char after FA-type key */
329*adc2b73dSToomas Soome 	keymap_entry_t	utf8;		/* equivalent UTF-8 code */
3307c478bd9Sstevel@tonic-gate };
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate /*
333*adc2b73dSToomas Soome  * The top byte is used to store the flags, leaving 24 bits for char.
334*adc2b73dSToomas Soome  */
335*adc2b73dSToomas Soome #define	KEYCHAR(c)	((c) & 0x00ffffff)
336*adc2b73dSToomas Soome #define	KEYFLAGS(c)	((c) & ~0x00ffffff)
337*adc2b73dSToomas Soome 
338*adc2b73dSToomas Soome /*
3397c478bd9Sstevel@tonic-gate  * The "special" entries' top 4 bits are defined below.	 Generally they are
3407c478bd9Sstevel@tonic-gate  * used with a 4-bit parameter (such as a bit number) in the low 4 bits.
3417c478bd9Sstevel@tonic-gate  * The bytes whose top 4 bits are 0x0 thru 0x7 happen to be ascii
3427c478bd9Sstevel@tonic-gate  * characters.	They are not special cased, but just normal cased.
3437c478bd9Sstevel@tonic-gate  */
3447c478bd9Sstevel@tonic-gate 
345*adc2b73dSToomas Soome #define	SPECIAL(h, l)	(((h) << 24) | (l))
346*adc2b73dSToomas Soome 
347*adc2b73dSToomas Soome #define	SHIFTKEYS SPECIAL(0x1, 0)
348*adc2b73dSToomas Soome 				/* thru 0x10F.	This key helps to determine */
3497c478bd9Sstevel@tonic-gate 				/* the translation table used.	The bit */
3507c478bd9Sstevel@tonic-gate 				/* position of its bit in "shiftmask" */
3517c478bd9Sstevel@tonic-gate 				/* is added to the entry, eg */
3527c478bd9Sstevel@tonic-gate 				/* SHIFTKEYS+LEFTCTRL.	When this entry is */
3537c478bd9Sstevel@tonic-gate 				/* invoked, the bit in "shiftmask" is */
3547c478bd9Sstevel@tonic-gate 				/* toggled.  Depending which tables you put */
3557c478bd9Sstevel@tonic-gate 				/* it in, this works well for hold-down */
3567c478bd9Sstevel@tonic-gate 				/* keys or press-on, press-off keys.  */
357*adc2b73dSToomas Soome #define	BUCKYBITS SPECIAL(0x2, 0)
358*adc2b73dSToomas Soome 				/* thru 0x20F.	This key determines the state */
3597c478bd9Sstevel@tonic-gate 				/* of one of the "bucky" bits above the */
3607c478bd9Sstevel@tonic-gate 				/* returned ASCII character.  This is */
3617c478bd9Sstevel@tonic-gate 				/* basically a way to pass mode-key-up/down */
3627c478bd9Sstevel@tonic-gate 				/* information back to the caller with each */
3637c478bd9Sstevel@tonic-gate 				/* "real" key depressed.  The concept, and */
3647c478bd9Sstevel@tonic-gate 				/* name "bucky" (derivation unknown) comes */
3657c478bd9Sstevel@tonic-gate 				/* from the MIT/SAIL "TV" system...they had */
3667c478bd9Sstevel@tonic-gate 				/* TOP, META, CTRL, and a few other bucky */
3677c478bd9Sstevel@tonic-gate 				/* bits.  The bit position of its bit in */
3687c478bd9Sstevel@tonic-gate 				/* "buckybits", minus 7, is added to the */
3697c478bd9Sstevel@tonic-gate 				/* entry; eg bit 0x00000400 is BUCKYBITS+3. */
3707c478bd9Sstevel@tonic-gate 				/* The "-7" prevents us from messing up the */
3717c478bd9Sstevel@tonic-gate 				/* ASCII char, and gives us 16 useful bucky */
3727c478bd9Sstevel@tonic-gate 				/* bits.  When this entry is invoked, */
3737c478bd9Sstevel@tonic-gate 				/* the designated bit in "buckybits" is */
3747c478bd9Sstevel@tonic-gate 				/* toggled.  Depending which tables you put */
3757c478bd9Sstevel@tonic-gate 				/* it in, this works well for hold-down */
3767c478bd9Sstevel@tonic-gate 				/* keys or press-on, press-off keys.  */
377*adc2b73dSToomas Soome #define	FUNNY SPECIAL(0x3, 0)	/* thru 0x30F.	This key does one of 16 funny */
3787c478bd9Sstevel@tonic-gate 				/* things based on the low 4 bits: */
379*adc2b73dSToomas Soome #define	NOP SPECIAL(0x3, 0x0)	/* This key does nothing. */
380*adc2b73dSToomas Soome #define	OOPS SPECIAL(0x3, 0x1) /* This key exists but is undefined. */
381*adc2b73dSToomas Soome #define	HOLE SPECIAL(0x3, 0x2) /* This key does not exist on the keyboard. */
3827c478bd9Sstevel@tonic-gate 				/* Its position code should never be */
3837c478bd9Sstevel@tonic-gate 				/* generated.  This indicates a software/ */
3847c478bd9Sstevel@tonic-gate 				/* hardware mismatch, or bugs. */
385*adc2b73dSToomas Soome #define	RESET SPECIAL(0x3, 0x6) /* Kbd was just reset */
386*adc2b73dSToomas Soome #define	ERROR SPECIAL(0x3, 0x7) /* Kbd just detected an internal error */
387*adc2b73dSToomas Soome #define	IDLE SPECIAL(0x3, 0x8) /* Kbd is idle (no keys down) */
388*adc2b73dSToomas Soome #define	COMPOSE SPECIAL(0x3, 0x9) /* This key is the Compose key. */
389*adc2b73dSToomas Soome #define	NONL SPECIAL(0x3, 0xA) /* This key not affected by Num Lock */
3907c478bd9Sstevel@tonic-gate /* Combinations 0x30B to 0x30F are reserved for non-parameterized functions */
3917c478bd9Sstevel@tonic-gate 
392*adc2b73dSToomas Soome #define	FA_CLASS SPECIAL(0x4, 0)
393*adc2b73dSToomas Soome 				/* thru 0x40F.	These are for "floating */
3947c478bd9Sstevel@tonic-gate 				/* accent" characters.	The low-order 4 bits */
3957c478bd9Sstevel@tonic-gate 				/* select one of those characters. */
3967c478bd9Sstevel@tonic-gate /* Definitions for the individual floating accents: */
397*adc2b73dSToomas Soome #define	FA_UMLAUT SPECIAL(0x4, 0x0)	/* umlaut accent */
398*adc2b73dSToomas Soome #define	FA_CFLEX SPECIAL(0x4, 0x1)	/* circumflex accent */
399*adc2b73dSToomas Soome #define	FA_TILDE SPECIAL(0x4, 0x2)	/* tilde accent */
400*adc2b73dSToomas Soome #define	FA_CEDILLA SPECIAL(0x4, 0x3)	/* cedilla accent */
401*adc2b73dSToomas Soome #define	FA_ACUTE SPECIAL(0x4, 0x4)	/* acute accent */
402*adc2b73dSToomas Soome #define	FA_GRAVE SPECIAL(0x4, 0x5)	/* grave accent */
403*adc2b73dSToomas Soome #define	FA_MACRON SPECIAL(0x4, 0x6)	/* macron accent */
404*adc2b73dSToomas Soome #define	FA_BREVE SPECIAL(0x4, 0x7)	/* breve accent */
405*adc2b73dSToomas Soome #define	FA_DOT SPECIAL(0x4, 0x8)	/* dot accent */
406*adc2b73dSToomas Soome #define	FA_SLASH SPECIAL(0x4, 0x9)	/* slash accent */
407*adc2b73dSToomas Soome #define	FA_RING SPECIAL(0x4, 0xa)	/* ring accent */
408*adc2b73dSToomas Soome #define	FA_APOSTROPHE SPECIAL(0x4, 0xb)	/* apostrophe accent */
409*adc2b73dSToomas Soome #define	FA_DACUTE SPECIAL(0x4, 0xc)	/* double acute accent */
410*adc2b73dSToomas Soome #define	FA_OGONEK SPECIAL(0x4, 0xd)	/* ogonek accent */
411*adc2b73dSToomas Soome #define	FA_CARON SPECIAL(0x4, 0xe)	/* caron accent */
4127c478bd9Sstevel@tonic-gate 
413*adc2b73dSToomas Soome #define	STRING SPECIAL(0x5, 0)	/* thru 0x50F.	The low-order 4 bits index */
4147c478bd9Sstevel@tonic-gate 				/* a table select a string to be returned, */
4157c478bd9Sstevel@tonic-gate 				/* char by char.  Each entry the table is */
4167c478bd9Sstevel@tonic-gate 				/* null terminated. */
4177c478bd9Sstevel@tonic-gate #define	KTAB_STRLEN	10	/* Maximum string length (including null) */
4187c478bd9Sstevel@tonic-gate /* Definitions for the individual string numbers: */
4197c478bd9Sstevel@tonic-gate #define	HOMEARROW	0x00
4207c478bd9Sstevel@tonic-gate #define	UPARROW		0x01
4217c478bd9Sstevel@tonic-gate #define	DOWNARROW	0x02
4227c478bd9Sstevel@tonic-gate #define	LEFTARROW	0x03
4237c478bd9Sstevel@tonic-gate #define	RIGHTARROW	0x04
4247c478bd9Sstevel@tonic-gate /* string numbers 5 thru F are available to users making custom entries */
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate /*
4277c478bd9Sstevel@tonic-gate  * In the following function key groupings, the low-order 4 bits indicate
4287c478bd9Sstevel@tonic-gate  * the function key number within the group, and the next 4 bits indicate
4297c478bd9Sstevel@tonic-gate  * the group.
4307c478bd9Sstevel@tonic-gate  */
431*adc2b73dSToomas Soome #define	FUNCKEYS	SPECIAL(0x6, 0)
432*adc2b73dSToomas Soome #define	LEFTFUNC SPECIAL(0x6, 0x0)	/* thru 0x60F.	The "left" group. */
433*adc2b73dSToomas Soome #define	RIGHTFUNC SPECIAL(0x6, 0x10)	/* thru 0x61F.	The "right" group. */
434*adc2b73dSToomas Soome #define	TOPFUNC SPECIAL(0x6, 0x20)	/* thru 0x62F.	The "top" group. */
435*adc2b73dSToomas Soome #define	BOTTOMFUNC SPECIAL(0x6, 0x30)	/* thru 0x63F.	The "bottom" group. */
4367c478bd9Sstevel@tonic-gate #define	LF(n)		(LEFTFUNC+(n)-1)
4377c478bd9Sstevel@tonic-gate #define	RF(n)		(RIGHTFUNC+(n)-1)
4387c478bd9Sstevel@tonic-gate #define	TF(n)		(TOPFUNC+(n)-1)
4397c478bd9Sstevel@tonic-gate #define	BF(n)		(BOTTOMFUNC+(n)-1)
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate /*
4427c478bd9Sstevel@tonic-gate  * The actual keyboard positions may not be on the left/right/top/bottom
4437c478bd9Sstevel@tonic-gate  * of the physical keyboard (although they usually are).
4447c478bd9Sstevel@tonic-gate  * What is important is that we have reserved 64 keys for function keys.
4457c478bd9Sstevel@tonic-gate  *
4467c478bd9Sstevel@tonic-gate  * Normally, striking a function key will cause the following escape sequence
4477c478bd9Sstevel@tonic-gate  * to be sent through the character stream:
4487c478bd9Sstevel@tonic-gate  *	ESC[0..9z
4497c478bd9Sstevel@tonic-gate  * where ESC is a single escape character and 0..9 indicate some number of
4507c478bd9Sstevel@tonic-gate  * digits needed to encode the function key as a decimal number.
4517c478bd9Sstevel@tonic-gate  */
452*adc2b73dSToomas Soome #define	PADKEYS		SPECIAL(0x7, 0)
453*adc2b73dSToomas Soome #define	PADEQUAL SPECIAL(0x7, 0x00)		/* keypad = */
454*adc2b73dSToomas Soome #define	PADSLASH SPECIAL(0x7, 0x01)		/* keypad / */
455*adc2b73dSToomas Soome #define	PADSTAR SPECIAL(0x7, 0x02)		/* keypad * */
456*adc2b73dSToomas Soome #define	PADMINUS SPECIAL(0x7, 0x03)		/* keypad - */
457*adc2b73dSToomas Soome #define	PADSEP SPECIAL(0x7, 0x04)		/* keypad,  */
458*adc2b73dSToomas Soome #define	PAD7 SPECIAL(0x7, 0x05)		/* keypad 7 */
459*adc2b73dSToomas Soome #define	PAD8 SPECIAL(0x7, 0x06)		/* keypad 8 */
460*adc2b73dSToomas Soome #define	PAD9 SPECIAL(0x7, 0x07)		/* keypad 9 */
461*adc2b73dSToomas Soome #define	PADPLUS SPECIAL(0x7, 0x08)		/* keypad + */
462*adc2b73dSToomas Soome #define	PAD4 SPECIAL(0x7, 0x09)		/* keypad 4 */
463*adc2b73dSToomas Soome #define	PAD5 SPECIAL(0x7, 0x0A)		/* keypad 5 */
464*adc2b73dSToomas Soome #define	PAD6 SPECIAL(0x7, 0x0B)		/* keypad 6 */
465*adc2b73dSToomas Soome #define	PAD1 SPECIAL(0x7, 0x0C)		/* keypad 1 */
466*adc2b73dSToomas Soome #define	PAD2 SPECIAL(0x7, 0x0D)		/* keypad 2 */
467*adc2b73dSToomas Soome #define	PAD3 SPECIAL(0x7, 0x0E)		/* keypad 3 */
468*adc2b73dSToomas Soome #define	PAD0 SPECIAL(0x7, 0x0F)		/* keypad 0 */
469*adc2b73dSToomas Soome #define	PADDOT SPECIAL(0x7, 0x10)		/* keypad . */
470*adc2b73dSToomas Soome #define	PADENTER SPECIAL(0x7, 0x11)		/* keypad Enter */
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4737c478bd9Sstevel@tonic-gate }
4747c478bd9Sstevel@tonic-gate #endif
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate #endif	/* _SYS_KBD_H */
477