[comp.windows.x] PC/AT Keyboard X Keysym Proposal

mikep@sco.COM (Mike Patnode) (02/08/91)

After much review and comments from this newsgroup and the X conference, 
I have rewritten this proposal.  It now includes definitions for the 
Lock keys as well as suggested 84 and 101 keysym keyboard maps.

Copies recieved by special interest parties and people who attended the BOF 
(Version 2.0) do not have the Num lock modifier definition.  I apologize
for that oversight.

Please let me hear your comments.

mp
----
Mike Patnode					The Santa Cruz Operation 
Software Engineer				400 Encinal Street
{ucscc,uunet}!sco!mikep	 mikep@sco.COM  	P.O. Box 1900
(408) 458-1422                                  Santa Cruz, CA 95061



			------ cut here -----





       Title :		    PC/AT Keyboard X Keysym Proposal


       Revision	:	    2.1


       Date :		    Jan	31 1991


       Status :		    DRAFT - for	review


       Synopsis	:	    This document describes a proposal for
			    standardizing the X11 Keysym mapping of
			    the	IBM PC/AT Keyboard.  The IBM 101
			    Keyboard is	one of the most	common
			    keyboards in the computer industry,	and
			    has	become very popular on X Terminals
			    and	non-Intel hardware platforms.  The
			    X11	Protocol is unable to describe the
			    AT Keyboard	for two	reasons.  There	are
			    not	enough unique keysyms to describe
			    all	the keys on the	keyboard, and there
			    is not a sufficient	mechanism to
			    consistently implement the Num Lock
			    key.  This document	proposes 12 new
			    keysyms to be added	to the standard
			    encoding, a	new Xlib implementation	of
			    the	Num Lock key and standard keysym
			    mapping tables for the IBM 101 and 84
			    key	keyboards.


       Author :
			    Mike Patnode
			    The	Santa Cruz Operation
			    mikep@sco.com



       Distribution :	    comp.windows.x













		  c 1991 The Santa Cruz	Operation, Inc.







				  - 2 -



       1.  Summary



       1.1  Introduction

       Since the majority of X Window research and development has
       been historically done on UNIX workstations there was never
       a great deal of emphasis	put upon Intel based personal
       computers.  Now,	with the emergence of faster Intel 386 and
       486 based machines, the PC/AT computer has become a viable
       UNIX workstation.  There	are an increasing number of
       software	vendors	who produce X servers for these	machines,
       as well as hardware manufactures	who have adopted the IBM AT
       keyboard	layout.	 Furthermore, a	complete set of	standard
       keysyms for the PC/AT keyboard will be needed to	aid
       portability in application binaries which comply	with the
       Intel386	Binary Compatibility Specification.



       1.2  Document History

	    Rev.   Date	       Description
	    _________________________________________________
	    1.0	   5 Jan 91    Created Document.  Posted to
			       comp.windows.x for comment.
	    1.1	   13 Jan 91   Minor revisions.	 Presented at
			       MIT X Technical Conference,
			       i386 X Developer's BOF.
			       Distributed with	USENET
			       comments	attached.
	    2.0	   31 Jan 91   Major revisions from X
			       Conference and BOF attendee
			       input.  Added Num Lock
			       proposal	and standard Keysym
			       layouts.
	    2.1	   7 Feb 91    Defined Mod2 as the Num Lock
			       modifier	entry.



       1.3  Desired Functionality

       The desired functionality of the	AT numeric keypad has been
       mostly defined by the DOS operating system and the IBM 84
       key keyboard which proceeded it.	 Most i386 UNIX	developers
       (as well	as many	other UNIX platforms) are interested in
       encouraging DOS developers to port their	applications to
       UNIX.




		  c 1991 The Santa Cruz	Operation, Inc.







				  - 1 -



       Although	the actual implementation tended to differ between
       hardware	vendors, the effect was	as follows.  When pressed
       by themselves, the keypad key scancodes would be	interpreted
       as cursor movement keys.	 If the	Shift key was pressed, the
       keys were interpreted as	numeric	keys.  When the	Num Lock
       key is on, the exact opposite interpretation is done, with
       the numeric values being	the default and	the cursor control
       keys sent in combination	with the Shift key.














































		  c 1991 The Santa Cruz	Operation, Inc.







				  - 2 -



       2.  New Keysyms



       2.1  X11	Protocol KEYSYM	Encoding

       The first part of this document proposes	12 new keysyms to
       be added	to the X11 KEYSYM Standard Encoding, which is
       defined in the X	Protocol.  As of Dec 10	1990, the public
       review period for the X Protocol	closed (ANSI working draft
       standard	X3H3.6/88-28R2).  In the event that this document
       is not taken into consideration by the working group, vendor
       specific	keysyms	will be	registered with	the X Consortium.


       2.2  Keypad Engravings

       The main	problem	arises from the	PC/AT numeric keypad.  Each
       of the numeric glyphs share a key with a	cursor or page
       control engraving.  The X Keysym	definition provides special
       keysyms for most	keypad keys which may also be present
       elsewhere on the	keyboard.  It does not provide keypad
       keysyms for the arrow or	page controls keys.  Hence, on the
       IBM AT keyboard,	an X programmer	cannot easily distinguish
       between the Up Arrow key	and the	Keypad Up Arrow	key unless
       the server writter provides non-standard	or unintuitive
       keysym names.

       The simple solution is to create	new standard keysyms for
       the PC/AT keyboards.   Not only are these keyboards in wide
       spread use, but this will also aid X application	programmers
       who are trying to comply	with the Intel386 BCS.

       Since the additional keysyms are	mostly for duplicate keys
       on the keyboard,	there should not be any	loss of
       functionality for existing applications.	 Applications which
       were using non-standard methods to differentiate	between	the
       keys may	need to	have old keymaps installed to be unaffected
       by these	changes.


       2.3  New	Keysyms

       There are 2 main	areas which this proposal covers.  One is
       simply a	common key for which there is no keysym	equivalent
       defined.	 The second is the 11 keypad keys which	have two
       engravings each.	 The keycodes (hex values) used	here are
       unused in the current keysym definition.	 These values are
       only suggestions	and are	not a requirement of the proposal.





		  c 1991 The Santa Cruz	Operation, Inc.







				  - 3 -



       There seems to be no X keysym which matches the SysReq key.

       0xFF15	XK_Sys_Req   System Request

       Next is the PC/AT keypad.  The current X	keysym set already
       defines some keypad keys	such as	KP_Enter and KP_Add.  The
       following keysyms are needed to complete	the definition.

       0xFF95	XK_KP_Home     Keypad Home
       0xFF96	XK_KP_Left     Keypad Left Arrow
       0xFF97	XK_KP_Up       Keypad Up Arrow
       0xFF98	XK_KP_Right    Keypad Right Arrow
       0xFF99	XK_KP_Down     Keypad Down Arrow
       0xFF9A	XK_KP_Prior    Keypad Page Up
       0xFF9B	XK_KP_Next     Keypad Page Down
       0xFF9C	XK_KP_End      Keypad End
       0xFF9D	XK_KP_Begin    Keypad Begin (No	engraving on AT	keyboard)
       0xFF9E	XK_KP_Insert   Keypad Insert
       0xFF9F	XK_KP_Delete   Keypad Delete

       Although	PC/AT Keyboard does not	have a unshifted engraving
       on the center keypad key	(numeric 5), this key is still used
       by many DOS applications.  The XK_KP_Begin keysym allows	the
       key to be easily	differentiated from the	numeric	5.  This
       also provides for AT keyboard variants which have a fifth
       key centered between the	arrow keys.  Prior and Next are
       used instead of "Page Up" and "Page Down" to remain
       consistent with existing	implementations. In order to cater
       to developers familiar with the AT keyboard engravings the
       following aliases should	be added as well.

       #define	 XK_Page_Up	   0xFF55   /* alias for XK_Prior */
       #define	 XK_Page_Down	   0xFF56   /* alias for XK_Next */
       #define	 XK_KP_Page_Up	   0xFF9A   /* alias for XK_KP_Prior */
       #define	 XK_KP_Page_Down   0xFF9B   /* alias for XK_KP_Next */



       2.4  84 Key Keyboards

       In order	to maintain backwards compatibility with existing
       keyboards, the keypad keysyms on	the IBM	84 key keyboard
       will remain the standard	keysyms.  Only XK_Sys_Req will be
       added to	the 84 keyboard	map.  XK_Begin is suggested for	the
       unshifted keysym	on the center keypad key.









		  c 1991 The Santa Cruz	Operation, Inc.







				  - 4 -



       3.  Lock	Keys



       3.1  Protocol Limitations

       The Num Lock key	is almost completely ignored by	the X
       Protocol.  The one concession is	that a keysym already
       exists.	According to the current Xlib and Protocol
       specifications, Num Lock	must be	implemented by the client
       application.  This is an	unacceptable solution.	An
       application should not have to deal with	the Num	Lock key
       any more	than it	must deal with the Caps	Lock key.  The Num
       Lock key	is a function of the keyboard, and is often
       implemented in the hardware itself.  It violates	the spirit
       of X Window development to suggest that the application must
       have some knowledge of the type of keyboard being used.	The
       Scroll Lock key suffers from some of the	same problems, but
       only that of implementing the actual locking mechanism.

       Unfortunately, few AT keyboards were available to the X
       Consortium when the Protocol was	being finalized, hence this
       problem was not brought into the	light until now.


       3.2  Num	Lock Implementations

       Many different approaches have been taken to attempt to deal
       with the	Num Lock key.  The most	common approach	has been to
       simply ignore the functionality,	since no implementation	is
       suggested by the	Protocol.  Some	servers	send both a Key
       Press and Release event while others only send the Press
       event, followed by the Release event on the second press.
       Most servers do turn on the LED associated with the key,	but
       very few	actually change	the keyboard mapping.  Some simple
       implementations set a modifier bit when the key is locked.
       Two current implementations are presented here, followed	by
       a third which is	a combination of the two.


       3.2.1  Server KEYCODES

       Thomas Roell's UNIX 386 X server	takes a	rather unique
       approach	to the Num Lock	key.   Tom added 11 more entries to
       his server's Keysym table.  These 11 entries are	to be used
       when the	Num Lock key is	pressed.  Hence, pressing the Num
       Lock key	actually causes	the same keys to have different
       Keycodes.  Unfortunately, this is a somewhat blatant
       violation of the	Protocol, in that a keycode no longer
       represents a physical (or logical) key.	Furthermore, it
       prevents	a client from being able to remap the keyboard



		  c 1991 The Santa Cruz	Operation, Inc.







				  - 5 -



       since the relationship between the different Keycodes cannot
       not be known.  Tom avoids setting a modifier bit	for fear of
       breaking	applications which use default translations.
       Translations are	defined	to be non-exclusive in the Xt
       specification, hence they should	not be affected	by the
       extra modifier bit.


       3.2.2  MODE SWITCH

       The AT&T	XWin server developers found a hole in the X
       Protocol	which allows them to legally implement the Num Lock
       key.  The Mode Switch keysym allows for a second	lock key
       which changes the mapping of the	keyboard.  The original
       intent was to provide a mechanism for multilingual keyboards
       to switch languages, but	this intent is not stated in the
       Protocol	definition.  Furthermore, with new international
       requirements it was found that one mode switch key would
       probably	not be sufficient for true multilingual	support.
       Thus multilingual use of	the Mode Switch	key will probably
       become archaic with future X releases.  With this in mind,
       the AT&T	developers simply mapped the Num Lock keycode to
       XK_Mode_switch, and added a set of Group	2 keysym entries
       for the numeric keypad keys.  The Mode Switch key also
       requires	the use	of a modifier bit.


       3.2.3  Num Lock Switch  The only	problem	with labeling the
       Num Lock	key as Mode Switch is one of semantics.	 It would
       be much cleaner if the Num Lock key sent	the XK_Num_Lock
       keysym and acted	as a Num Lock key, rather than the Num Lock
       key sending the XK_Mode_switch keysym and acting	as a Num
       Lock.  The simple solution is to	modify the interpretation
       of XK_Num_Lock at the Xlib level, such that it is
       functionally equivalent to XK_Mode_switch.  The actual
       source changes are trivial.

       Original	code segment from lib/X/XKeyBind.c:InitModMap()

	    /* Now find	any Mod<n> modifier acting as the Group	modifier */
	    dpy->mode_switch = 0;
	    n *= 4;
	    for	(i = 3*map->max_keypermod; i < n; i++) {
		for (j = 0; j <	dpy->keysyms_per_keycode; j++) {
		    sym	= KeyCodetoKeySym(dpy, map->modifiermap[i], j);
	!	    if (sym == XK_Mode_switch)
			dpy->mode_switch |= 1 << (i / map->max_keypermod);
		}
	    }

       Suggested modification to lib/X/XKeyBind.c:InitModMap()



		  c 1991 The Santa Cruz	Operation, Inc.







				  - 6 -



	    /* Now find	any Mod<n> modifier acting as the Group	modifier */
	    dpy->mode_switch = 0;
	    n *= 4;
	    for	(i = 3*map->max_keypermod; i < n; i++) {
		for (j = 0; j <	dpy->keysyms_per_keycode; j++) {
		    sym	= KeyCodetoKeySym(dpy, map->modifiermap[i], j);
	!	    if (sym == XK_Mode_switch || sym ==	XK_Num_Lock)
			dpy->mode_switch |= 1 << (i / map->max_keypermod);
		}
	    }


       Two more	changes	need to	be applied to the server to
       complete	the Num	Lock key functionality.	 These are
       necessary for the above implementation.

	  + The	server should only send	a Press	event when Num Lock
	    is toggled on, and only send a Release event when the
	    key	is toggled off.

	  + If an LED labeled "Num Lock" exists	on the keyboard, it
	    should be turned on	and off	in accordance with the
	    status of the key.

	  + The	Num_Lock keysym	shall be defined as Mod2.


       3.3  Scroll Lock

       The actual semantics of the Scroll Lock key are poorly
       defined,	if they	are defined at all.  This should continue
       to be left up to	the client application,	since no standard
       interpretation has come to light.  Yet, to be consistent
       with the	treatment of the Caps Lock and Num Lock	keys, the
       same rules need to be applied.


	  + The	server should only send	a Press	event when Scroll
	    Lock is toggled on,	and only send a	Release	event when
	    the	key is toggled off.

	  + If an LED labeled "Scroll Lock" exists on the keyboard,
	    it should be turned	on and off in accordance with the
	    status of the key.










		  c 1991 The Santa Cruz	Operation, Inc.







				  - 7 -



       3.4  Caps Lock

       This is only included for completeness.	The following is
       not defined in the X Protocol, but was in the sample
       implementation.

	  + The	server should only send	a Press	event when Caps
	    Lock is toggled on,	and only send a	Release	event when
	    the	key is toggled off.

	  + If an LED labeled "Caps Lock" exists on the	keyboard,
	    it should be turned	on and off in accordance with the
	    status of the key.









































		  c 1991 The Santa Cruz	Operation, Inc.







				  - 8 -



       4.  Keyboard Mapping



       4.1  84 Key Keyboard

       The following is	the suggested X	Keysym mapping for the IBM
       U.S. English 84 key keyboard.  The numerical values
       represent IBM XT	scancodes.  The	third and fourth columns
       are used	by the Num Lock	mode switch.  Columns with only	one
       or two entries are expanded according to	Section	5 of the
       Protocol.

       Scancode	  Group	1			     Group 2
       _______________________________________________________________________
       1:	  XK_Escape
       2:	  XK_1		    XK_exclam
       3:	  XK_2		    XK_at
       4:	  XK_3		    XK_numbersign
       5:	  XK_4		    XK_dollar
       6:	  XK_5		    XK_percent
       7:	  XK_6		    XK_asciicircum
       8:	  XK_7		    XK_ampersand
       9:	  XK_8		    XK_asterisk
       10:	  XK_9		    XK_parenleft
       11:	  XK_0		    XK_parenright
       12:	  XK_minus	    XK_underscore
       13:	  XK_equal	    XK_plus
       14:	  XK_BackSpace
       15:	  XK_Tab
       16:	  XK_Q
       17:	  XK_W
       18:	  XK_E
       19:	  XK_R
       20:	  XK_T
       21:	  XK_Y
       22:	  XK_U
       23:	  XK_I
       24:	  XK_O
       25:	  XK_P
       26:	  XK_bracketleft    XK_braceleft
       27:	  XK_bracketright   XK_braceright
       28:	  XK_Return
       29:	  XK_Control_L
       30:	  XK_A
       31:	  XK_S
       32:	  XK_D
       33:	  XK_F
       34:	  XK_G
       35:	  XK_H
       36:	  XK_J
       37:	  XK_K


		  c 1991 The Santa Cruz	Operation, Inc.







				  - 9 -



       38:	  XK_L
       39:	  XK_semicolon	    XK_colon
       40:	  XK_quoteright	    XK_quotedbl
       41:	  XK_quoteleft	    XK_asciitilde
       42:	  XK_Shift_L
       43:	  XK_backslash	    XK_bar
       44:	  XK_Z
       45:	  XK_X
       46:	  XK_C
       47:	  XK_V
       48:	  XK_B
       49:	  XK_N
       50:	  XK_M
       51:	  XK_comma	    XK_less
       52:	  XK_period	    XK_greater
       53:	  XK_slash	    XK_question
       54:	  XK_Shift_R
       55:	  XK_KP_Multiply    XK_Print
       56:	  XK_Alt_L
       57:	  XK_space
       58:	  XK_Caps_Lock
       59:	  XK_F1
       60:	  XK_F2
       61:	  XK_F3
       62:	  XK_F4
       63:	  XK_F5
       64:	  XK_F6
       65:	  XK_F7
       66:	  XK_F8
       67:	  XK_F9
       68:	  XK_F10
       69:	  XK_Num_Lock
       70:	  XK_Scroll_Lock
       71:	  XK_Home	    XK_KP_7	     XK_KP_7	     XK_Home
       72:	  XK_Up		    XK_KP_8	     XK_KP_8	     XK_Up
       73:	  XK_Prior	    XK_KP_9	     XK_KP_9	     XK_Prior
       74:	  XK_KP_Subtract
       75:	  XK_Left	    XK_KP_4	     XK_KP_4	     XK_Left
       76:	  XK_Begin	    XK_KP_5	     XK_KP_5	     XK_Begin
       77:	  XK_Right	    XK_KP_6	     XK_KP_6	     XK_Right
       78:	  XK_KP_Add
       79:	  XK_End	    XK_KP_1	     XK_KP_1	     XK_End
       80:	  XK_Down	    XK_KP_2	     XK_KP_2	     XK_Down
       81:	  XK_Next	    XK_KP_3	     XK_KP_3	     XK_Next
       82:	  XK_Insert	    XK_KP_0	     XK_KP_0	     XK_Insert
       83:	  XK_Delete	    XK_KP_Decimal    XK_KP_Decimal   XK_Delete
       84:	  XK_Sys_Req







		  c 1991 The Santa Cruz	Operation, Inc.







				  - 10 -



       4.2  101	Key Keyboard

       The following is	the suggested X	Keysym mapping for the IBM
       U.S. English 101	key keyboard.  The numerical values
       represent AT keyboard scancodes when in XT mode.	 Note that
       some AT keyboard	keys send multibyte scancode sequences.
       The third and fourth columns are	used by	the Num	Lock mode
       switch.	Columns	with only one or two entries are expanded
       according to Section 5 of the Protocol.

       Scancode	   Group 1			      Group 2
       ___________________________________________________________________________
       1:	   XK_Escape
       2:	   XK_1		     XK_exclam
       3:	   XK_2		     XK_at
       4:	   XK_3		     XK_numbersign
       5:	   XK_4		     XK_dollar
       6:	   XK_5		     XK_percent
       7:	   XK_6		     XK_asciicircum
       8:	   XK_7		     XK_ampersand
       9:	   XK_8		     XK_asterisk
       10:	   XK_9		     XK_parenleft
       11:	   XK_0		     XK_parenright
       12:	   XK_minus	     XK_underscore
       13:	   XK_equal	     XK_plus
       14:	   XK_BackSpace
       15:	   XK_Tab
       16:	   XK_Q
       17:	   XK_W
       18:	   XK_E
       19:	   XK_R
       20:	   XK_T
       21:	   XK_Y
       22:	   XK_U
       23:	   XK_I
       24:	   XK_O
       25:	   XK_P
       26:	   XK_bracketleft    XK_braceleft
       27:	   XK_bracketright   XK_braceright
       28:	   XK_Return
       29:	   XK_Control_L
       30:	   XK_A
       31:	   XK_S
       32:	   XK_D
       33:	   XK_F
       34:	   XK_G
       35:	   XK_H
       36:	   XK_J
       37:	   XK_K
       38:	   XK_L
       39:	   XK_semicolon	     XK_colon
       40:	   XK_quoteright     XK_quotedbl


		  c 1991 The Santa Cruz	Operation, Inc.







				  - 11 -



       41:	   XK_quoteleft	     XK_asciitilde
       42:	   XK_Shift_L
       43:	   XK_backslash	     XK_bar
       44:	   XK_Z
       45:	   XK_X
       46:	   XK_C
       47:	   XK_V
       48:	   XK_B
       49:	   XK_N
       50:	   XK_M
       51:	   XK_comma	     XK_less
       52:	   XK_period	     XK_greater
       53:	   XK_slash	     XK_question
       54:	   XK_Shift_R
       55:	   XK_KP_Multiply
       56:	   XK_Alt_L
       57:	   XK_space
       58:	   XK_Caps_Lock
       59:	   XK_F1
       60:	   XK_F2
       61:	   XK_F3
       62:	   XK_F4
       63:	   XK_F5
       64:	   XK_F6
       65:	   XK_F7
       66:	   XK_F8
       67:	   XK_F9
       68:	   XK_F10
       69:	   XK_Num_Lock
       70:	   XK_Scroll_Lock
       71:	   XK_KP_Home	     XK_KP_7	      XK_KP_7	      XK_KP_Home
       72:	   XK_KP_Up	     XK_KP_8	      XK_KP_8	      XK_KP_Up
       73:	   XK_KP_Prior	     XK_KP_9	      XK_KP_9	      XK_KP_Prior
       74:	   XK_KP_Subtract
       75:	   XK_KP_Left	     XK_KP_4	      XK_KP_4	      XK_KP_Left
       76:	   XK_KP_Begin	     XK_KP_5	      XK_KP_5	      XK_KP_Begin
       77:	   XK_KP_Right	     XK_KP_6	      XK_KP_6	      XK_KP_Right
       78:	   XK_KP_Add
       79:	   XK_KP_End	     XK_KP_1	      XK_KP_1	      XK_KP_End
       80:	   XK_KP_Down	     XK_KP_2	      XK_KP_2	      XK_KP_Down
       81:	   XK_KP_Next	     XK_KP_3	      XK_KP_3	      XK_KP_Next
       82:	   XK_KP_Insert	     XK_KP_0	      XK_KP_0	      XK_KP_Insert
       83:	   XK_KP_Delete	     XK_KP_Decimal    XK_KP_Decimal   XK_KP_Delete
       84:	   XK_Sys_Req
       87:	   XK_F11
       88:	   XK_F12
       96 71:	   XK_Home
       96 72:	   XK_Up
       96 73:	   XK_Prior
       96 75:	   XK_Left
       96 76:	   XK_Begin



		  c 1991 The Santa Cruz	Operation, Inc.







				  - 12 -



       96 77:	   XK_Right
       96 79:	   XK_End
       96 80:	   XK_Down
       96 81:	   XK_Next
       96 82:	   XK_Insert
       96 83:	   XK_Delete
       96 28:	   XK_KP_Enter
       96 29:	   XK_Control_R
       97 29 69:   XK_Pause
       96 42 55:   XK_Print
       96 53:	   XK_KP_Divide
       96 56:	   XK_Alt_R
       96 70:	   XK_Break









































		  c 1991 The Santa Cruz	Operation, Inc.




-- 
Mike Patnode					The Santa Cruz Operation 
Software Engineer				400 Encinal Street
{ucscc,uunet}!sco!mikep	 mikep@sco.COM  	P.O. Box 1900
(408) 458-1422                                  Santa Cruz, CA 95061

mikep@sco.COM (Mike Patnode) (02/18/91)

Here is version 3.0.  This contains a new Num Lock proposal which does
not use Mode Switch.  Please read and return/post comments ASAP.

mp

----------------- cut here --------------------






       Title :              PC/AT Keyboard X Keysym Proposal


       Revision :           3.0


       Date :               17 Feb 1991


       Status :             DRAFT - for approval


       Synopsis :           This document describes a proposal for
                            standardizing the X11 Keysym mapping of
                            the IBM PC/AT Keyboard.  The IBM 101
                            Keyboard is one of the most common
                            keyboards in the computer industry, and
                            has become very popular on X Terminals
                            and non-Intel hardware platforms.  The
                            X11 Protocol is unable to describe the
                            AT Keyboard for two reasons.  There are
                            not enough unique keysyms to describe
                            all the keys on the keyboard, and there
                            is not a sufficient mechanism to
                            consistently implement the Num Lock
                            key.  This document proposes 12 new
                            keysyms to be added to the standard
                            encoding, a new Xlib implementation of
                            the Num Lock key and standard keysym
                            mapping tables for the IBM 101 and 84
                            key keyboards.


       Author :             Mike Patnode
                            The Santa Cruz Operation
                            400 Encinal Street
                            P.O. Box 1900
                            Santa Cruz, CA, 95061
                            (408) 458-1422
                            mikep@sco.COM



       Distribution :       comp.windows.x










                  c 1991 The Santa Cruz Operation, Inc.







       PC/AT Keyboard X Keysym Proposal                 17 Feb 1991



       1.  Summary



       1.1  Introduction

       Since the majority of X Window research and development has
       been historically done on UNIX workstations there was never
       a great deal of emphasis put upon Intel based personal
       computers.  Now, with the emergence of faster Intel 386 and
       486 based machines, the PC/AT computer has become a viable
       UNIX workstation.  There are an increasing number of
       software vendors who produce X servers for these machines,
       as well as hardware manufactures who have adopted the IBM AT
       keyboard layout.  Furthermore, a complete set of standard
       keysyms for the PC/AT keyboard will be needed to aid
       portability in application binaries which comply with the
       Intel386 Binary Compatibility Specification.



       1.2  Document History

            Rev.   Date        Description
            _________________________________________________
            1.0     5 Jan 91   Created Document.  Posted to
                               comp.windows.x for comment.
            1.1    13 Jan 91   Minor revisions.  Presented at
                               MIT X Technical Conference,
                               i386 X Developer's BOF.
                               Distributed with USENET
                               comments attached.
            2.0    31 Jan 91   Major revisions from X
                               Conference and BOF attendee
                               input.  Added Num Lock
                               proposal and standard Keysym
                               layouts.
            2.1     7 Feb 91   Defined Mod2 as the Num Lock
                               modifier entry.
            3.0    16 Feb 91   Completely rewrote Num Lock
                               proposal.  Changed to not use
                               Mode Switch in order to
                               provide compatibility with
                               existing European keymap
                               tables.









       Revision 3.0        DRAFT - for approval              Page 1







       PC/AT Keyboard X Keysym Proposal                 17 Feb 1991



       1.3  Desired Functionality

       The desired functionality of the AT numeric keypad has been
       mostly defined by the DOS operating system and the IBM 84
       key keyboard which proceeded it.  Most i386 UNIX developers
       (as well as many other UNIX platforms) are interested in
       encouraging DOS developers to port their applications to
       UNIX.

       Although the actual implementation tended to differ between
       hardware vendors, the effect was as follows.  When pressed
       by themselves, the keypad key scancodes would be interpreted
       as cursor movement keys.  If the Shift key was pressed, the
       keys were interpreted as numeric keys.  When the Num Lock
       key is on, the exact opposite interpretation is done, with
       the numeric values being the default and the cursor control
       keys sent in combination with the Shift key.



       2.  New Keysyms



       2.1  X11 Protocol KEYSYM Encoding

       The first part of this document proposes 12 new keysyms to
       be added to the X11 KEYSYM Standard Encoding, which is
       defined in the X Protocol.  As of Dec 10 1990, the public
       review period for the X Protocol closed (ANSI working draft
       standard X3H3.6/88-28R2).  In the event that this document
       is not taken into consideration by the working group, vendor
       specific keysyms will be registered with the X Consortium.


       2.2  Keypad Engravings

       The main problem arises from the PC/AT numeric keypad.  Each
       of the numeric glyphs share a key with a cursor or page
       control engraving.  The X Keysym definition provides special
       keysyms for most keypad keys which may also be present
       elsewhere on the keyboard.  It does not provide keypad
       keysyms for the arrow or page controls keys.  Hence, on the
       IBM AT keyboard, an X programmer cannot easily distinguish
       between the Up Arrow key and the Keypad Up Arrow key unless
       the server writter provides non-standard or unintuitive
       keysym names.

       The simple solution is to create new standard keysyms for
       the PC/AT keyboards.   Not only are these keyboards in wide
       spread use, but this will also aid X application programmers



       Revision 3.0        DRAFT - for approval              Page 2







       PC/AT Keyboard X Keysym Proposal                 17 Feb 1991



       who are trying to comply with the Intel386 BCS.

       Since the additional keysyms are mostly for duplicate keys
       on the keyboard, there should not be any loss of
       functionality for existing applications.  Applications which
       were using non-standard methods to differentiate between the
       keys may need to have old keymaps installed to be unaffected
       by these changes.


       2.3  New Keysyms

       There are 2 main areas which this proposal covers.  One is
       simply a common key for which there is no keysym equivalent
       defined.  The second is the 11 keypad keys which have two
       engravings each.  The keycodes (hex values) used here are
       unused in the current keysym definition.  These values are
       only suggestions and are not a requirement of the proposal.

       There seems to be no X keysym which matches the SysReq key.

       0xFF15   XK_Sys_Req   System Request

       Next is the PC/AT keypad.  The current X keysym set already
       defines some keypad keys such as KP_Enter and KP_Add.  The
       following keysyms are needed to complete the definition.

       0xFF95   XK_KP_Home     Keypad Home
       0xFF96   XK_KP_Left     Keypad Left Arrow
       0xFF97   XK_KP_Up       Keypad Up Arrow
       0xFF98   XK_KP_Right    Keypad Right Arrow
       0xFF99   XK_KP_Down     Keypad Down Arrow
       0xFF9A   XK_KP_Prior    Keypad Page Up
       0xFF9B   XK_KP_Next     Keypad Page Down
       0xFF9C   XK_KP_End      Keypad End
       0xFF9D   XK_KP_Begin    Keypad Begin (No engraving on AT keyboard)
       0xFF9E   XK_KP_Insert   Keypad Insert
       0xFF9F   XK_KP_Delete   Keypad Delete

       Although PC/AT Keyboard does not have a unshifted engraving
       on the center keypad key (numeric 5), this key is still used
       by many DOS applications.  The XK_KP_Begin keysym allows the
       key to be easily differentiated from the numeric 5.  This
       also provides for AT keyboard variants which have a fifth
       key centered between the arrow keys.  Prior and Next are
       used instead of "Page Up" and "Page Down" to remain
       consistent with existing implementations. In order to cater
       to developers familiar with the AT keyboard engravings the
       following aliases should be added as well.

       #define   XK_Page_Up        0xFF55   /* alias for XK_Prior */



       Revision 3.0        DRAFT - for approval              Page 3







       PC/AT Keyboard X Keysym Proposal                 17 Feb 1991



       #define   XK_Page_Down      0xFF56   /* alias for XK_Next */
       #define   XK_KP_Page_Up     0xFF9A   /* alias for XK_KP_Prior */
       #define   XK_KP_Page_Down   0xFF9B   /* alias for XK_KP_Next */



       2.4  84 Key Keyboards

       In order to maintain backwards compatibility with existing
       keyboards, the keypad keysyms on the IBM 84 key keyboard
       will remain the standard keysyms.  Only XK_Sys_Req will be
       added to the 84 keyboard map.  XK_Begin is suggested for the
       unshifted keysym on the center keypad key.



       3.  Lock Keys



       3.1  Protocol Limitations

       The Num Lock key is almost completely ignored by the X
       Protocol.  The one concession is that a keysym already
       exists.  According to the current Xlib and Protocol
       specifications, Num Lock must be implemented by the client
       application. An application should not have to deal with the
       Num Lock key any more than it must deal with the Caps Lock
       key.  So much like Caps Lock, Num Lock should be implemented
       in Xlib.  Yet, there does need to be some cooperation with
       the server.  The Scroll Lock key suffers from some of the
       same problems as Num Lock, but only that of implementing the
       actual locking mechanism.

       Unfortunately, few AT keyboards were available to the X
       Consortium when the Protocol was being finalized, hence this
       problem was not brought into the light until now.


       3.2  Previous Implementations

       Many different approaches have been taken to attempt to deal
       with the Num Lock key.  The most common approach has been to
       simply ignore the functionality, since no implementation is
       suggested by the Protocol.  Some servers send both a Key
       Press and Release event while others only send the Press
       event, followed by the Release event on the second press.
       Most servers do turn on the LED associated with the key, but
       very few actually change the keyboard mapping.  Some simple
       implementations set a modifier bit when the key is locked.
       A Num Lock standard must adhere to the existing X protocol



       Revision 3.0        DRAFT - for approval              Page 4







       PC/AT Keyboard X Keysym Proposal                 17 Feb 1991



       as much as possible, and not break existing applications and
       server implementations when avoidable.


       3.3  Num Lock Modifier

       The most obvious implementation of the Num Lock key is to
       follow the example set by the Caps Lock key.  The alphabetic
       keysyms, which are arbitrarily defined in
       lib/X/XKeyBind.c:XConvertCase(), are treated special by the
       protocol.  In short, XConvertCase() is called whenever a
       alphabetic keysym needs to be converted to lower case. The
       keysyms are left capitalized if the appropriate modifier bit
       is set.  This is implemented in
       lib/X/XKeyBind.c:XTranslateKey().

       The Num Lock key should be treated the exact same way, with
       the keymap table being used for most conversions.  By
       assigning Num Lock to a modifier bit known by Xlib, a simple
       change can be made to lib/X/XKeyBind.c:XTranslateKey() to
       support Num Lock functionality.  In the context diff below,
       a simple macro has been defined to identify a keypad key.
       Note that only the numeric engravings need be checked.
       Before any other modifier translation takes place, the
       Is_KP_Keysym() check is made.  If the Num Lock modifier bit
       is set, the second column of the keymap table is returned.
       If the Shift modifier bit is set as well, the first column
       is used.  Note that a Shift by itself will still access the
       upper engravings on the keypad.

       *** /a/X11R4/mit/lib/X/XKeyBind.c       Mon Dec 11 16:09:42 1989
       --- XKeyBind.c  Sat Feb 16 22:20:56 1991
       ***************
       *** 17,22 ****
       --- 17,28 ----
         #define AllMods (ShiftMask|LockMask|ControlMask| \
                        Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)

       + #define NumLockMask Mod2Mask
       +
       + /* Watch the multiple evaluation */
       + #define Is_KP_Keysym(k) ((((k) >= XK_KP_0) && ((k) <= XK_KP_9)) || \
       +                               ((k) == XK_KP_Decimal))
       +
         static ComputeMaskFromKeytrans();
         static int Initialize();
         static void XConvertCase();
       ***************
       *** 276,282 ****
                 syms += 2;
                 per -= 2;



       Revision 3.0        DRAFT - for approval              Page 5







       PC/AT Keyboard X Keysym Proposal                 17 Feb 1991



             }
       !     if (!(modifiers & ShiftMask) &&
                     (!(modifiers & LockMask) || (dpy->lock_meaning == NoSymbol))) {
                 if ((per == 1) || (syms[1] == NoSymbol))
                     XConvertCase(dpy, syms[0], keysym_return, &usym);
       --- 281,289 ----
                 syms += 2;
                 per -= 2;
             }
       !     if ((modifiers & NumLockMask) && (per > 1) && Is_KP_Keysym(syms[1])) {
       !         *keysym_return = (modifiers & ShiftMask) ? syms[0] : syms[1];
       !     } else if (!(modifiers & ShiftMask) &&
                 (!(modifiers & LockMask) || (dpy->lock_meaning == NoSymbol))) {
                 if ((per == 1) || (syms[1] == NoSymbol))
                     XConvertCase(dpy, syms[0], keysym_return, &usym);


       If there are no KP_ keysyms in the second column of the
       mapkey table (IE: The keyboard does not use NumLock) Mod2
       will have no effect on the keyboard binding.

       Three changes also need to be applied to the server to
       complete the Num Lock key functionality.  These are
       necessary for the above implementation and are somewhat
       obvious.

          + The server should only send a Press event when Num Lock
            is toggled on, and only send a Release event when the
            key is toggled off.

          + If an LED labeled "Num Lock" exists on the keyboard, it
            should be turned on and off in accordance with the
            status of the key.

          + The XK_Num_Lock keysym shall be defined as Mod2.


       3.4  Scroll Lock

       The actual semantics of the Scroll Lock key are poorly
       defined, if they are defined at all.  This should continue
       to be left up to the client application, since no standard
       interpretation has come to light.  Yet, to be consistent
       with the treatment of the Caps Lock and Num Lock keys, the
       same rules need to be applied.


          + The server should only send a Press event when Scroll
            Lock is toggled on, and only send a Release event when
            the key is toggled off.




       Revision 3.0        DRAFT - for approval              Page 6







       PC/AT Keyboard X Keysym Proposal                 17 Feb 1991



          + If an LED labeled "Scroll Lock" exists on the keyboard,
            it should be turned on and off in accordance with the
            status of the key.


       3.5  Caps Lock

       This is only included for completeness.  The following is
       not defined in the X Protocol, but was in the sample
       implementation.

          + The server should only send a Press event when Caps
            Lock is toggled on, and only send a Release event when
            the key is toggled off.

          + If an LED labeled "Caps Lock" exists on the keyboard,
            it should be turned on and off in accordance with the
            status of the key.



       4.  Keyboard Mapping



       4.1  84 Key Keyboard

       The following is the suggested X Keysym keymap table for the
       IBM U.S. English 84 key keyboard.  The numerical values
       represent IBM XT scancodes.  Columns with only one entry are
       expanded according to Section 5 of the Protocol.

       Scancode   Keysyms
       ___________________________________________
       1:         XK_Escape
       2:         XK_1              XK_exclam
       3:         XK_2              XK_at
       4:         XK_3              XK_numbersign
       5:         XK_4              XK_dollar
       6:         XK_5              XK_percent
       7:         XK_6              XK_asciicircum
       8:         XK_7              XK_ampersand
       9:         XK_8              XK_asterisk
       10:        XK_9              XK_parenleft
       11:        XK_0              XK_parenright
       12:        XK_minus          XK_underscore
       13:        XK_equal          XK_plus
       14:        XK_BackSpace
       15:        XK_Tab
       16:        XK_Q
       17:        XK_W
       18:        XK_E


       Revision 3.0        DRAFT - for approval              Page 7







       PC/AT Keyboard X Keysym Proposal                 17 Feb 1991



       19:        XK_R
       20:        XK_T
       21:        XK_Y
       22:        XK_U
       23:        XK_I
       24:        XK_O
       25:        XK_P
       26:        XK_bracketleft    XK_braceleft
       27:        XK_bracketright   XK_braceright
       28:        XK_Return
       29:        XK_Control_L
       30:        XK_A
       31:        XK_S
       32:        XK_D
       33:        XK_F
       34:        XK_G
       35:        XK_H
       36:        XK_J
       37:        XK_K
       38:        XK_L
       39:        XK_semicolon      XK_colon
       40:        XK_quoteright     XK_quotedbl
       41:        XK_quoteleft      XK_asciitilde
       42:        XK_Shift_L
       43:        XK_backslash      XK_bar
       44:        XK_Z
       45:        XK_X
       46:        XK_C
       47:        XK_V
       48:        XK_B
       49:        XK_N
       50:        XK_M
       51:        XK_comma          XK_less
       52:        XK_period         XK_greater
       53:        XK_slash          XK_question
       54:        XK_Shift_R
       55:        XK_KP_Multiply    XK_Print
       56:        XK_Alt_L
       57:        XK_space
       58:        XK_Caps_Lock
       59:        XK_F1
       60:        XK_F2
       61:        XK_F3
       62:        XK_F4
       63:        XK_F5
       64:        XK_F6
       65:        XK_F7
       66:        XK_F8
       67:        XK_F9
       68:        XK_F10
       69:        XK_Num_Lock



       Revision 3.0        DRAFT - for approval              Page 8







       PC/AT Keyboard X Keysym Proposal                 17 Feb 1991



       70:        XK_Scroll_Lock
       71:        XK_Home           XK_KP_7
       72:        XK_Up             XK_KP_8
       73:        XK_Prior          XK_KP_9
       74:        XK_KP_Subtract
       75:        XK_Left           XK_KP_4
       76:        XK_Begin          XK_KP_5
       77:        XK_Right          XK_KP_6
       78:        XK_KP_Add
       79:        XK_End            XK_KP_1
       80:        XK_Down           XK_KP_2
       81:        XK_Next           XK_KP_3
       82:        XK_Insert         XK_KP_0
       83:        XK_Delete         XK_KP_Decimal
       84:        XK_Sys_Req

       4.2  101 Key Keyboard

       The following is the suggested X Keysym keymap table for the
       IBM U.S. English 101 key keyboard.  The numerical values
       represent AT keyboard scancodes when in XT mode.  Note that
       some AT keyboard keys send multibyte scancode sequences.
       Columns with only one entry are expanded according to
       Section 5 of the Protocol.

       Scancode    Keysyms
       ____________________________________________
       1:          XK_Escape
       2:          XK_1              XK_exclam
       3:          XK_2              XK_at
       4:          XK_3              XK_numbersign
       5:          XK_4              XK_dollar
       6:          XK_5              XK_percent
       7:          XK_6              XK_asciicircum
       8:          XK_7              XK_ampersand
       9:          XK_8              XK_asterisk
       10:         XK_9              XK_parenleft
       11:         XK_0              XK_parenright
       12:         XK_minus          XK_underscore
       13:         XK_equal          XK_plus
       14:         XK_BackSpace
       15:         XK_Tab
       16:         XK_Q
       17:         XK_W
       18:         XK_E
       19:         XK_R
       20:         XK_T
       21:         XK_Y
       22:         XK_U
       23:         XK_I
       24:         XK_O
       25:         XK_P


       Revision 3.0        DRAFT - for approval              Page 9







       PC/AT Keyboard X Keysym Proposal                 17 Feb 1991



       26:         XK_bracketleft    XK_braceleft
       27:         XK_bracketright   XK_braceright
       28:         XK_Return
       29:         XK_Control_L
       30:         XK_A
       31:         XK_S
       32:         XK_D
       33:         XK_F
       34:         XK_G
       35:         XK_H
       36:         XK_J
       37:         XK_K
       38:         XK_L
       39:         XK_semicolon      XK_colon
       40:         XK_quoteright     XK_quotedbl
       41:         XK_quoteleft      XK_asciitilde
       42:         XK_Shift_L
       43:         XK_backslash      XK_bar
       44:         XK_Z
       45:         XK_X
       46:         XK_C
       47:         XK_V
       48:         XK_B
       49:         XK_N
       50:         XK_M
       51:         XK_comma          XK_less
       52:         XK_period         XK_greater
       53:         XK_slash          XK_question
       54:         XK_Shift_R
       55:         XK_KP_Multiply
       56:         XK_Alt_L
       57:         XK_space
       58:         XK_Caps_Lock
       59:         XK_F1
       60:         XK_F2
       61:         XK_F3
       62:         XK_F4
       63:         XK_F5
       64:         XK_F6
       65:         XK_F7
       66:         XK_F8
       67:         XK_F9
       68:         XK_F10
       69:         XK_Num_Lock
       70:         XK_Scroll_Lock
       71:         XK_KP_Home        XK_KP_7
       72:         XK_KP_Up          XK_KP_8
       73:         XK_KP_Prior       XK_KP_9
       74:         XK_KP_Subtract
       75:         XK_KP_Left        XK_KP_4
       76:         XK_KP_Begin       XK_KP_5



       Revision 3.0        DRAFT - for approval             Page 10







       PC/AT Keyboard X Keysym Proposal                 17 Feb 1991



       77:         XK_KP_Right       XK_KP_6
       78:         XK_KP_Add
       79:         XK_KP_End         XK_KP_1
       80:         XK_KP_Down        XK_KP_2
       81:         XK_KP_Next        XK_KP_3
       82:         XK_KP_Insert      XK_KP_0
       83:         XK_KP_Delete      XK_KP_Decimal
       84:         XK_Sys_Req
       87:         XK_F11
       88:         XK_F12
       96 71:      XK_Home
       96 72:      XK_Up
       96 73:      XK_Prior
       96 75:      XK_Left
       96 76:      XK_Begin
       96 77:      XK_Right
       96 79:      XK_End
       96 80:      XK_Down
       96 81:      XK_Next
       96 82:      XK_Insert
       96 83:      XK_Delete
       96 28:      XK_KP_Enter
       96 29:      XK_Control_R
       97 29 69:   XK_Pause
       96 42 55:   XK_Print
       96 53:      XK_KP_Divide
       96 56:      XK_Alt_R
       96 70:      XK_Break


























       Revision 3.0        DRAFT - for approval             Page 11




-- 
Mike Patnode					The Santa Cruz Operation 
Software Engineer				400 Encinal Street
{ucscc,uunet}!sco!mikep	 mikep@sco.COM  	P.O. Box 1900
(408) 458-1422                                  Santa Cruz, CA 95061