(c)  Copyright 1989 Commodore-Amiga, Inc.   All rights reserved.
The information contained herein is subject to change without notice, and 
is provided "as is" without warranty of any kind, either expressed or implied.  
The entire risk as to the use of this information is assumed by the user.



                       INTERNATIONAL KEYBOARD INPUT

                    Eric Cotton and Carolyn Scheppner


        The Amiga computers are sold internationally with a variety of
     local keyboards which match the standards of particular countries.
     The 1.2 Enhancer manual contains diagrams of the keyboards which
     are currently distributed.  If you look at the diagrams, you will
     see that some letters and special symbols are in different
     physical positions on the various keyboards.  For instance, on
     the German and Italian keyboards, the Y and Z keys are swapped
     when compared to the USA keyboard.  Since the physical position
     of a key determines the raw key code that it generates, straight
     RAWKEY input is not internationally compatible.  Pressing the second
     key on the fifth row will generate the same raw key code on all
     Amiga keyboards, but will be decoded as a Z on a US keyboard and
     as a Y on a German.

        The 1.2 Amiga console device supports national keyboards by 
     providing mapping of raw key codes to the proper ASCII characters 
     and strings as specified in a Keymap.  In addition, the console 
     device provides handling of the "dead keys" used to generate accented 
     characters.  Any keyboard input which is processed by the console
     device will be automatically translated to the installed keymap.
     The new 1.2 Setmap command is used to install the default keymap
     to be used by the console device.  If you wish to experiment with
     the national keymaps, the KeyToy program on Extras 1.2 provides
     a graphic presentation of the various keyboards.
     
        All of the national Keymaps, including USA, contain dead keys. 
     Basically, a dead key is a key that produces no output until a second
     key is pressed.  Thus the dead key modifies the output of another key.
     Often a dead key is used to indicate that a particular accent mark is 
     to be placed on the next character typed.  The ASCII values for these 
     characters are all greater than 127. They are listed in the International
     Character Codes table in the AmigaDOS manual.  If a dead key is used to 
     request an invalid accent for a character, the normal unaccented 
     character results.

        If you look at the U.S. keyboard diagram in the Enhancer manual,
     you'll see that the F, G, H, J, and K keys (shadowed) are defined 
     as dead keys.  In the diagram, various accent marks are printed in 
     the lower half of each of these keys.  Pressing Alt and one of these
     shadowed keys is a request for the illustrated accent to be placed 
     on the next character you type.

       For example, try typing these with the default usa keymap:

         ALT/F (') then A  results in an A accented with '
         ALT/H (^) then E  results in an E accented with ^
         ALT/J (~) then C  results in a plain C (invalid accent for C)


        Under 1.2, the console.device, IDCMP VANILLAKEY, and AmigaDOS
     CON: and RAW: all provide automatic handling of dead keys and
     translation of raw keycodes to ASCII based on the current keymap.
     If your software requires non-VANILLA keys such as the cursor and
     function keys, using console device keyboard input in your Intuition 
     window will allow you to receive the escape sequences generated
     by these keys.  If you are using IDCMP RAWKEY input in international
     software, you must properly use the console device's RawKeyConvert()
     function to get keymap translation and dead key handling.  See the
     example DeadKeyConvert() in the 1.2 Enhancer manual (P. 65) or the 
     1.2 Readmes for more on this.  Use NULL for the kmap argument to get 
     translation to the currently installed Keymap.
 
        Be sure to test your code with ASCII characters greater than 127 
     such as accented characters like Alt-F-A wherever your code accepts 
     keyboard input to ensure that your logic and data structures work properly 
     with high ASCII values.  In addition, test your code after using 
     SetMap to install various keymaps, using the Enhancer manual keyboard
     diagrams as a guide for what the keycaps would show in that country.
     You won't be able to test all of the keys of some national keyboards,
     but you can test enough keys to be sure you are getting translation.

        The following information is a supplement to chapter 8, The Console 
     Device, in the Rom Kernel Manual: Libraries and Devices, which describes 
     the Keymap format and console.device handling of dead keys.  



Dead-Class Keys

The term "dead-class key" refers to keys that either modify or can themselves
be modified by other dead-class keys.  There are two types of dead-class keys:
dead and deadable.  A dead key is one which can modify the key pressed 
immediately following it.  For example, in all keymaps the H key acts as a 
carat ("^") dead key when pressed along with the Alt or Shift-Alt qualifiers.
When followed by the A key for instance, the combination will produce the 
accented character @@ (international character code $E2).  A deadable key is
is one that can be pre-fixed by a dead key.  The A key in this example is a 
deadable key.  Thus, a dead key can only affect the output of a deadable key.

For any key that is to have a dead-class function, whether dead or deadable,
the qualifier KCF_DEAD flag must be included in the entry for the key in the
KeyMapTypes table.  The KCF_DEAD type may also be used in conjunction with
the other qualifiers.  Furthermore, the key's KeyMap table entry must contain
the longword address of the key's dead-key descriptor data area in place of
the usual 4 ASCII character mapping.


Consider the following example KeyMap excerpt:


			Example 1: Dead-Class Keys

	new LoKeyMapTypes:
		DC.B	KCF_DEAD+KCF_SHIFT+KCF_ALT+KCF_CONTROL  ;aA (Key 20)
			    ...			;(more...)
		DC.B	KCF_DEAD+KCF_SHIFT+KCF_ALT+KCF_CONTROL	;hH (Key 25)
			    ...			;(more...)

	new LoKeyMap:
		DC.L	key20			; a, A, ae, AE
                            ...                 ;(more...)
		DC.L	key25			;h, H, dead ^
			    ...			;(more...)

	;------ possible dead keys
	key25:
		DC.B	0,'h',0,'H'		;h, H
		DC.B	DPF_DEAD,3,DPF_DEAD,3	;dead ^
		DC.B	0,$08,0,$08,0,$88,0,$88	;control translation
			    ...			;(more...)

	;------ deadable keys (modified by dead keys)
	key20:
		DC.B	DPF_MOD,key20u-key20	;deadable flag, number of
						;bytes from start of key20
						;descriptor to start of un-
						;shifted data

		DC.B	DPF_MOD,key20s-key20	;deadable flag, number of
						;bytes from start of key20
						;descriptor to start of shift-
						;ed data

		DC.B	0,$E6,0,$C6		;null flags followed by rest
		DC.B	0,$01,0,$01,0,$81,0,$81	;of values (ALT, CTRL...)
	key20u:
		DC.B	'a',$E0,$E1,$E2,$E3,$E4	;'a' alone and characters to
						;output when key alone is
						;prefixed by a dead key
	key20s:
		DC.B	'A',$C0,$C1,$C2,$C3,$C4	;SHIFTed 'a' and characters to
						;output when SHIFTed key is
						;prefixed by a dead key



In the example, key 25 (the H key) is a dead key and key 20 (the A key) is
a deadable key.  Both keys use the addresses of their descriptor data areas as
entries in the LoKeyMap table.  The LoKeyMapTypes table says that there are
four qualifiers for both: the requisite KCF_DEAD, as well as KCF_SHIFT,
KCF_ALT, and KCF_CONTROL.  The number of qualifiers determine length and
arrangement of the descriptor data areas for each key.  Table 1 below shows
how to interpret the KeyMapTypes for various combinations of the qualifier
bits.  For each possible position a pair of bytes is needed.  The first byte
in each pair tells how to interpret the second byte.


		Table 1: Dead Key Qualifier Bits

If type 	Then the pair of bytes in this position in the dead-class key
byte is:	descriptor data is output when the key is pressed along with:

NOQUAL		alone	-	-	-	-	-	-	-
A		alone	A	-	-	-	-	-	-
C		alone	C	-	-	-	-	-	-
S		alone	S	-	-	-	-	-	-
A+C		alone	A	C	A+C	-	-	-	-
A+S		alone	S	A	A+S	-	-	-	-
C+S		alone	S	C	C+S	-	-	-	-
S+A+C (VANILLA)	alone	S	A	S+A	C	C+S	C+A	C+S+A

	NOTE: the abbreviations A, C, S stand for ALT, Control, and Shift,
	respectively.  Also note that the ordering is reversed from that in
	the normal KeyMap table.


Because keys 20 and 25 each use three qualifier bits (not including KCF_DEAD),
according to the table there must be 8 pairs of data, arranged as shown.
Had only KCF_ALT been set, for instance, (not including KCF_DEAD), just two
pairs would have been needed: key alone and Alt-key.

As mentioned earlier, the first byte of data pair in the descriptor data area 
specifies how to interpret the second byte.  There are three possible type
values: 0, DPF_DEAD and DPF_MOD.  In Example 1, DPF_DEAD appears in the data
for key 25,  while DPF_MOD is used for key 20.  It is the use of these flags
which determines whether a dead-class key has dead or deadable function. A
value of zero causes the unrestricted output of the following byte.

If the type byte is DPF_DEAD, then that particular key combination (determined
by the placement of the pair of bytes in the data table) is dead and will 
modify the output of the next key pressed, if deadable.  How it modifies is
controlled by the second byte of the pair which is used as an index into
parts of the data area for ALL the deadable keys (DPF_MOD set).

Before going further, an understanding of the structure of a descriptor data
area wherein DPF_MOD is set for one or more of its members is necessary.
Referring to the example, we see that DPF_MOD is set for the first and second
pairs of bytes.  According to its LoKeyMapTypes entry, and using Table 1 as
a guide, these pairs represent the alone and Shifted values for the key.  When
DPF_MOD is set, the byte immediately following the flag must be the offset
from the start of the key's descriptor data area to the start of a table of
bytes describing the characters to output when this key combination is preceded
by a dead key.  This is where the index mentioned above comes in.  The
value of the index from a prefixing dead key is used to determine which of the
bytes from the deadable keys special table to output.  The byte in the index+1
position is sent out.  (The byte in the first position is the value to output if
the key was not prefixed by a dead key.)  Thus, if Alt-H is pressed (carat) and
then Shift-A, an @@ will be output.  This is because: 

	o  The byte pair for the Alt position of the H key (key 25) is
	   DPF_DEAD,3 so the index is 3.
	o  The byte pair for the SHIFT position of the A key (key 20) is
	   DPF_MOD,key20s-key20, so we refer to the table-of-bytes at key20s.
	o  The third+1 byte of the table-of-bytes is $C2, a @@ character.

Note that the number of bytes in the table-of-bytes for all deadable keys must
be equal to the highest index value of all dead keys plus 1.





        
     

