From: deal@tempus.Kodak.Com (Stephen M. Deal)
Subject: Re: keyboard type
Keywords: Sun Type3?, Sun Type4?, HP-HIL?, HP-PC?
Reply-To: deal@Kodak.COM
Organization: Eastman Kodak Company
Distribution: na
Date: Sun, 13 Dec 92 01:54:28 GMT

In article <1992Dec9.174911.5846@dartvax.dartmouth.edu>, andyb@coat.com
(Andy Behrens) writes:
|> It is not neccesary to write a C program when you want to determine
|> the
|> keyboard type.  

You are right, but what you posted didn't tell me what type of keyboard
the user is 'touching'. We have Sun Type 3 and Type 4 keyboards and HP
7xx machines with both HP-HIL and HP-PC keyboards. So...

Attached is a script I wrote so that users could use an xterm to emulate
a vt100 and the keypad was mapped correctly on Suns and HPs. I needed to
do the mapping correctly regardless of where they ran vtterm (local or
remote). This script only affects the one window so other keyboard
mappings for other windows are not disturbed.

I will be the first to admit that the manner in which I determine the
keyboard type is a kludge but I couldn't find a better way. If anyone
has a suggestion or knows how to determine the keyboard type in a more
direct and reliable manner, please let me know.

I did appreciate Andy posting the xrdb -symbols command. I have never
seen that command and I am sure that it will come in handy one day.

Regards,

  ======================================================================
  | Steve Deal	 	| Internet: deal@Kodak.COM		       |
  | Eastman Kodak Co.	| UUCP:     ...rutgers!rit!kodak!tempus!deal   |
  | Engr. Systems Div.	| Voice:    (716) 726 - 5396		       |
  | mailcode: 35108	| FAX:	    (716) 726 - 7406	               |
  | 901 Elmgrove Road	| 					       |
  | Rochester, NY	| 					       |
  | 	   14653-5108   |					       |
  ======================================================================
    Disclaimer:	"Everyone is entitled to an opinion, 
		 the above is mine and not that of my employer."

-------------------cut here---------------------------cut here----------------
#!/bin/sh
#
# Name:	vtterm 1.0
# Author: Steve Deal				Eastman Kodak Company
#						Engineering Systems Division
#						Rochester, NY
#
# Description:	Determines physical type of keyboard being used then
# 		maps arrow keys and keypad for VT100 emulation.
#
# Currently supports: Sun Type3 and Type4, HP-HIL, and HP-PC keyboards
#

#  Determine machine architecture to set the xmodmap and xterm binary paths
#
if [ `uname -s` = "SunOS" ]; then				# SunOS
  XTERM_BINPATH=/usr/openwin/demo		# OW2
  XMODMAP_BINPATH=/usr/openwin/bin
  if [ -f /usr/openwin/bin/olwmslave ]; then	# OW3
    XTERM_BINPATH=/usr/openwin/bin
  fi
else			# Default to "std" X paths for all other machines
  XTERM_BINPATH=/usr/bin/X11
  XMODMAP_BINPATH=/usr/bin/X11
fi

#  Now determine the keyboard type attached to the Xserver
#
LINE=`${XMODMAP_BINPATH}/xmodmap -pk |grep 95`

if [ -n "`echo $LINE | grep Clear`" ]; then
  KBDTYPE=hphil
elif [ -n "`echo $LINE | grep backslash`" ]; then
  if [ -n "`echo $LINE | grep brokenbar`" ]; then
    KBDTYPE=suntype4
  else
    KBDTYPE=suntype3
  fi
else
  KBDTYPE=hppc
fi

#  Invoke an xterm with the correct mappings
#
case $KBDTYPE in
  suntype3)
# Keypad mapping for Sun Type3 keyboard
# 	PF1	PF2	PF3	PF4 is F7
# 	 7	 8	 9	 -  is F8
#	 4	 5	 6	 ,  is F9
#	 1	 2	 3
#	 0	 .	Enter
#
# 	Up=F3	down=F4	left=F5	right=F6
#
${XTERM_BINPATH}/xterm \
-title "VT100 for Sun Type3 keyboard" \
-n "VT100" \
-xrm "xterm*scrollBar:off" \
-xrm "xterm*font:10x20" \
-xrm "xterm*VT100*font1:6x10" \
-xrm "xterm*VT100*font2:8x13" \
-xrm "xterm*VT100*font3:10x20" \
-xrm "xterm*VT100*font4:12x24" \
-xrm "xterm*VT100.Translations:#override \
<Key>R1:    string("0x01b") string("OP") \n\
<Key>R2:    string("0x01b") string("OQ") \n\
<Key>R3:    string("0x01b") string("OR") \n\
<Key>F7:    string("0x01b") string("OS") \n\
<Key>R13:   string("0x01b") string("Op") \n\
<Key>Left:  string("0x01b") string("Oq") \n\
<Key>R11:   string("0x01b") string("Or") \n\
<Key>Right: string("0x01b") string("Os") \n\
<Key>R7:    string("0x01b") string("Ot") \n\
<Key>Up:    string("0x01b") string("Ou") \n\
<Key>R9:    string("0x01b") string("Ov") \n\
<Key>R4:    string("0x01b") string("Ow") \n\
<Key>R5:    string("0x01b") string("Ox") \n\
<Key>R6:    string("0x01b") string("Oy") \n\
<Key>R15:   string("0x01b") string("OM") \n\
<Key>F8:    string("0x01b") string("Om") \n\
<Key>F9:    string("0x01b") string("Ol") \n\
<Key>Down:  string("0x01b") string("On") \n\
<Key>F2:    string("0x01b") string("[29~") \n\
<Key>F3:    string("0x01b") string("OA") \n\
<Key>F4:    string("0x01b") string("OB") \n\
<Key>F5:    string("0x01b") string("OD") \n\
<Key>F6:    string("0x01b") string("OC")" $@ & ;;


  suntype4)
# Keypad mapping for Sun Type4 keyboard
# 	Up	down	left	right
# 	PF1	PF2	PF3	PF4
# 	 7	 8	 9	 - is Shift +
#	 4	 5	 6	 , is +
#	 1	 2	 3
#	     0		 .	Enter
#
${XMODMAP_BINPATH}/xmodmap -e "keycode 57 = KP_Decimal"
${XTERM_BINPATH}/xterm \
-title "VT100 keypad for Sun Type4 keyboard" \
-n "VT100" \
-xrm "xterm*scrollBar:off" \
-xrm "xterm*font:10x20" \
-xrm "xterm*VT100*font1:6x10" \
-xrm "xterm*VT100*font2:8x13" \
-xrm "xterm*VT100*font3:10x20" \
-xrm "xterm*VT100*font4:12x24" \
-xrm "xterm*VT100.Translations:#override \
<Key>R4:    		string("0x01b") string("OP") \n\
<Key>R5:    		string("0x01b") string("OQ") \n\
<Key>R6:    		string("0x01b") string("OR") \n\
<Key>KP_Subtract:	string("0x01b") string("OS") \n\
<Key>Insert:   		string("0x01b") string("Op") \n\
<Key>R13:  		string("0x01b") string("Oq") \n\
<Key>Down:   		string("0x01b") string("Or") \n\
<Key>R15: 		string("0x01b") string("Os") \n\
<Key>Left:    		string("0x01b") string("Ot") \n\
<Key>R11:    		string("0x01b") string("Ou") \n\
<Key>Right:    		string("0x01b") string("Ov") \n\
<Key>R7:    		string("0x01b") string("Ow") \n\
<Key>Up:    		string("0x01b") string("Ox") \n\
<Key>R9:    		string("0x01b") string("Oy") \n\
<Key>KP_Enter:		string("0x01b") string("OM") \n\
Shift<Key>KP_Add:	string("0x01b") string("Om") \n\
<Key>KP_Add:		string("0x01b") string("Ol") \n\
<Key>KP_Decimal:	string("0x01b") string("On") \n\
<Key>F21:    		string("0x01b") string("OA") \n\
<Key>F22:    		string("0x01b") string("OB") \n\
<Key>F23:    		string("0x01b") string("OD") \n\
<Key>Num_Lock:    	string("0x01b") string("OC")" $@ & ;;

  hphil)
# Keypad mapping for HP HIL keyboard
#       PF1     PF2     PF3     PF4
#        7       8       9       - 
#        4       5       6       ,
#        1       2       3
#            0           .      Enter
#
${XTERM_BINPATH}/xterm \
-title "VT100 for HP HIL keyboard" \
-n "VT100" \
-xrm "xterm*scrollBar:on" \
-xrm "xterm*font:10x20" \
-xrm "xterm*VT100*font1:8x13" \
-xrm "xterm*VT100*font2:9x15" \
-xrm "xterm*VT100*font3:10x20" \
-xrm "xterm*VT100*font4:12x24" \
-xrm "xterm*VT100.Translations:#override \
<Key>BackSpace:		string("") \n\
<Key>KP_Multiply:	string("0x01b") string("OP") \n\
<Key>KP_Divide:		string("0x01b") string("OQ") \n\
<Key>KP_Add:		string("0x01b") string("OR") \n\
<Key>KP_Subtract:	string("0x01b") string("OS") \n\
<Key>KP_0:		string("0x01b") string("Op") \n\
<Key>KP_1:		string("0x01b") string("Oq") \n\
<Key>KP_2:		string("0x01b") string("Or") \n\
<Key>KP_3:		string("0x01b") string("Os") \n\
<Key>KP_4:		string("0x01b") string("Ot") \n\
<Key>KP_5:		string("0x01b") string("Ou") \n\
<Key>KP_6:		string("0x01b") string("Ov") \n\
<Key>KP_7:		string("0x01b") string("Ow") \n\
<Key>KP_8:		string("0x01b") string("Ox") \n\
<Key>KP_9:		string("0x01b") string("Oy") \n\
<Key>KP_Tab:		string("0x01b") string("OM") \n\
<Key>KP_Enter:		string("0x01b") string("Om") \n\
<Key>KP_Separator:	string("0x01b") string("Ol") \n\
<Key>KP_Decimal:	string("0x01b") string("On") \n\ 
<Key>Up:		string("0x01b") string("OA") \n\ 
<Key>Down:		string("0x01b") string("OB") \n\ 
<Key>Left:		string("0x01b") string("OD") \n\ 
<Key>Right:		string("0x01b") string("OC")" $@ & ;;

  hppc)
# Keypad mapping for HP PC keyboard
#       PF1     PF2     PF3     PF4
#        7       8       9       - is Shift+
#        4       5       6       , is +
#        1       2       3
#            0           .      Enter
#
${XTERM_BINPATH}/xterm \
-title "VT100 for HP PC keyboard" \
-n "VT100" \
-xrm "xterm*scrollBar:on" \
-xrm "xterm*font:10x20" \
-xrm "xterm*VT100*font1:8x13" \
-xrm "xterm*VT100*font2:9x15" \
-xrm "xterm*VT100*font3:10x20" \
-xrm "xterm*VT100*font4:12x24" \
-xrm "xterm*VT100.Translations:#override \
<Key>BackSpace:		string("") \n\
<Key>Num_Lock:		string("0x01b") string("OP") \n\
<Key>KP_Divide:		string("0x01b") string("OQ") \n\
<Key>KP_Multiply:	string("0x01b") string("OR") \n\
<Key>KP_Subtract:	string("0x01b") string("OS") \n\
<Key>KP_0:		string("0x01b") string("Op") \n\
<Key>KP_1:		string("0x01b") string("Oq") \n\
<Key>KP_2:		string("0x01b") string("Or") \n\
<Key>KP_3:		string("0x01b") string("Os") \n\
<Key>KP_4:		string("0x01b") string("Ot") \n\
<Key>KP_5:		string("0x01b") string("Ou") \n\
<Key>KP_6:		string("0x01b") string("Ov") \n\
<Key>KP_7:		string("0x01b") string("Ow") \n\
<Key>KP_8:		string("0x01b") string("Ox") \n\
<Key>KP_9:		string("0x01b") string("Oy") \n\
Shift<Key>KP_Add:	string("0x01b") string("Om") \n\
<Key>KP_Add:		string("0x01b") string("Ol") \n\
<Key>KP_Enter:		string("0x01b") string("OM") \n\
<Key>KP_Decimal:	string("0x01b") string("On") \n\ 
<Key>Up:		string("0x01b") string("OA") \n\ 
<Key>Down:		string("0x01b") string("OB") \n\ 
<Key>Left:		string("0x01b") string("OD") \n\ 
<Key>Right:		string("0x01b") string("OC")" $@ & ;;

  *) echo "Could not determine type of keyboard, exiting..." exit;;

esac