Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

375 lines
16 KiB

  1. A keyboard layout description file is a text file that fully describes a
  2. keyboard layout for Windows NT.
  3. The tool KBDTOOL.EXE parses the text file, and produces C sourcce files that
  4. can be compiled and linked to form the keyboard layout DLL itself.
  5. The keyboard layout description file consists of different sections:
  6. KBD The header
  7. VERSION Version
  8. MODIFIERS Optional: Modifier Keys other than Ctrl, Shift, Alt
  9. SHIFTSTATE Describes columns of the LAYOUT section
  10. LAYOUT Defines each key's scancode, VK and characters etc.
  11. DEADKEY Optional: how dead keys combine with base characters
  12. KEYNAME Names of standard keys
  13. KEYNAME_EXT Names of extended keys
  14. KEYNAME_DEAD Names of dead keys
  15. ENDKBD Keyword indicating the end of the keyboard layout description
  16. comments // anywhere on the line or ; as the first non-space char
  17. These sections normally appear in this order but some changes in order are
  18. possible but not recommended.
  19. There may be more than one DEADKEY section.
  20. KBD
  21. ===
  22. Syntax: KBD <name> "<description>"
  23. KBD - required keyword starts the description
  24. <name> - output C source files names derived from this. The files will
  25. be kbd<name>.h kbd<name>.rc kbd<name>.c & kbd<name>.def
  26. <name> is typically 2 to 5 letters, but can any length > 0
  27. <description> - Becomes the VER_FILEDESCRIPTION_STR resource in the
  28. final DLL after " Keyboard Layout" is appended.
  29. Example: KBD CAN "Canadian National Standard"
  30. Comments
  31. ========
  32. // comments
  33. can appear on the end of any line, or on a line by themselves, in
  34. any section
  35. ; comments
  36. can appear on the end of any line, or on a line by themselves, except
  37. within the LAYOUT section
  38. VERSION
  39. =======
  40. Currently this is ignored, but should be 1.0 since future versions of kbdtool
  41. may require this.
  42. This section appears as a single line:
  43. VERSION 1.0
  44. ATTRIBUTES
  45. ==========
  46. This section begins with a line containing the word ATTRIBUTES, followed by
  47. a list of attributes, one per line. Each of these attributes corresponds to
  48. an KLF_ flag (defined in winuserp.h) that may be specified in the registry
  49. under MACHINE\System\CurrentControlSet\Control\Keyboard Layouts\*\Attributes
  50. The attributes are:
  51. LRM_RLM Left Shift + Backspace will generate a Left-to-Right marker
  52. Right Shift + Backspace will generate a Right-to-Left marker
  53. This is useful mainl for Arabic and Hebrew languages.
  54. Corresponds to the KLF_LRM_RLM flag.
  55. SHIFTLOCK CapsLock will be turned off by pressing either shift key.
  56. This corresponds to the KLF_SHIFTLOCK flag.
  57. ALTGR Pressing the right-hand Alt key will actually generate the key
  58. sequence Left Control + Right Alt, thereby obtaining a third
  59. modifier state known as "AltGr" which is used by many European
  60. layouts.
  61. This bit need not be explicity listed here: if any Control + Alt
  62. modifiers are listed in the MODIFIERS section (described below),
  63. then this attribute will be automatically defined.
  64. When the layout is loaded, the attributes specified in this section will be
  65. combined with those obtained from the layout's Attributes value in the registry.
  66. The section should be followed by a blank line. It is terminated by a
  67. keyword starting the next section (which should be MODIFIERS).
  68. MODIFIERS
  69. =========
  70. This section defines keys that may be held down to alter the character produced
  71. by typing another key, in addition to the standard modifiers Shift, Ctrl and
  72. Alt (AltGr is the same as Alt + Ctrl).
  73. Each consists of a VK value and a hexadecimal single-bit value greater than 4.
  74. For example, the infamous Canadian National Standard CAN/CSA-Z243.200-92 layout,
  75. kbdcan.txt, specifies that the VK_OEM_8 key is another modifier, identified by
  76. the value 0x08, by having a "MODIFIER" line like this: "OEM_8 8"
  77. SHIFTSTATE
  78. ==========
  79. This section is a list of Shift/Ctrl/Alt key combinations, represented by a
  80. hexadecimal number formed by OR-ing in zero or more of the following bits:
  81. 0x1 Shift
  82. 0x2 Ctrl
  83. 0x4 Alt
  84. 0x8 - 0x80 Optional modifiers as defined in the previous "MODIFIERS" section
  85. Each entry in the list is on a separate line: the first line is the modifier
  86. state for column 4 of the "LAYOUT" section that follows, the second line is
  87. the modifier state for LAYOUT column 5, the third line is for LAYOUT column 6
  88. and so on. This is usually commented to make it clearer, eg:
  89. 0 ;Column 4 :
  90. 1 ;Column 5 : Shift
  91. 6 ;Column 6 : Control Alt
  92. 2 ;Column 7 : Control
  93. 3 ;Column 8 : Shift Control
  94. In the example above, AltGr (Alt + Ctrl) character will be found in column 6
  95. of the following "LAYOUT" section.
  96. LAYOUT
  97. ======
  98. This describes each key, one row per key.
  99. Each row contains either 2 columns (for keys with no character) or more than 5
  100. columns. Each column is separated by whitespace.
  101. Column 1 - Scancode
  102. -------------------
  103. The scancode emitted by the keyboard hardware in hexadecimal.
  104. This is usually 2 digits.
  105. Extended or enhanced keys, which produce a 2-byte sequence starting 0xE0 or
  106. 0xE1 usually obtain default VK values hard-coded into kbdtool, but these may be
  107. overridden by specifying a scanocde in the form E0xx or E1xx. The only example
  108. of this so far is in kbdcan.txt (the notorious Canadian National Standard
  109. CAN/CSA-Z243.200-92 layout)
  110. Sometimes the scancode will appear as "-1", which indicates that this row is
  111. information supplementing the preceding row: see SGCAPS under Column 3.
  112. Column 2 - Virtual key value
  113. ----------------------------
  114. This is the VK value, as passed in Windows messages such as WM_KEYDOWN.
  115. The value is either a VK literal with the first 3 letters ("VK_") removed, or
  116. it is an ASCII character 0 through 9 or A through Z for those VK values that
  117. are not explicitly defined in our header files.
  118. Column 3 - CapsLock and SGCAPS
  119. ------------------------------
  120. This is a bitwise combination of the following values:
  121. Value Name Appearance
  122. 0x01 CAPLOK "1"
  123. 0x02 SGCAPS "SGCap"
  124. 0x04 CAPLOKALTGR "4" but usually appears added to CAPLOK as "5"
  125. 0x08 KANALOK unknown (some FE meaning)
  126. 0x80 GRPSELTAP unused
  127. CAPLOK: means that this key is affected by the CapsLock state (or ShiftLock state)
  128. SGCap: means that this key is affected by the Shift state and the CapsLock
  129. state, but in different ways. This is described in two lines: the First
  130. is marked SGCap in column 3 and indicates how the character values are
  131. determined according to whether a Shift key is down or not. The Second
  132. line is marked with -1 in column 1 (scancode) and indicates how character
  133. values for the same key are determined according to the CapsLock state.
  134. This occurs in the Swiss German layout, kbdsg.txt, hence the term SGCaps
  135. but it is also used in various middle-eastern layouts as well.
  136. CAPLOKALTGR: means that the CapsLock state affects those chracaters that are
  137. produced with AltGr too. AltGr (the right hand Alt, or Ctrl+Alt), is
  138. a "third shift" that is used to make a key generate more than just an
  139. upper an lowercase version of the same character. If a key generates
  140. one character while AltGr is held down and another character while AltGr
  141. and Shift are held down, then the CAPLOKALTGR bit says that CapsLock
  142. state has the same effect as changing the Shift key state. This bit
  143. usually appears together with the CAPLOK bit on the same key to form
  144. the value "5" in column 3.
  145. KANALOK: means ????
  146. GRPSELTAP: not used (residue from an early attempt at the CAN/CSA layout)
  147. Columns 4 and beyond - character values
  148. ---------------------------------------
  149. Each column from column 4 onward represents a character value for a specific
  150. Shift/Ctrl/Alt/CapsLock state. They appear either literally (in the US English
  151. Windows codepage 1252), or as hexadecimal Unicode values.
  152. Characters that have a "@" suffix are "dead keys". These will generate a
  153. diacritic (accent mark) which will not appear at the time it is typed, but
  154. will be applied to the next letter typed. See WM_DEADCHAR. The ways in which
  155. each diacritic combines with the next character typed are defined in "DEADKEY"
  156. sections that follow this "LAYOUT" section.
  157. The "SHIFTSTATE" section that precedes the "LAYOUT" section defines the
  158. Shift/Ctrl/Alt combination for each column.
  159. Default Entries
  160. ----------------
  161. Certain keys which are common to all keyboard layouts have default entries
  162. created for them by kbdtool.exe.
  163. These may be overridden by specifying them in the LAYOUT section.
  164. These are the default entries:
  165. VK_BACK 0 0008 0008
  166. VK_ESCAPE 0 001b 001b
  167. VK_RETURN 0 000d 000d
  168. VK_SPACE 0 ' ' ' '
  169. VK_CANCEL 0 0003 0003
  170. TAB 0 0009 0009
  171. ADD 0 + +
  172. DIVIDE 0 / /
  173. MULTIPLY 0 * *
  174. SUBTRACT 0 - -
  175. NUMPAD0 0 0
  176. NUMPAD1 0 1
  177. NUMPAD2 0 2
  178. NUMPAD3 0 3
  179. NUMPAD4 0 4
  180. NUMPAD5 0 5
  181. NUMPAD6 0 6
  182. NUMPAD7 0 7
  183. NUMPAD8 0 8
  184. NUMPAD9 0 9
  185. Entry order
  186. -----------
  187. The way the LAYOUT entries are ordered is important in determining how the
  188. Win32 API VkKeyScanEx() functions.
  189. Order of numeric keypad entries.
  190. The most important thing is that any Numeric Keypad Virtual keys (VK_DECIMAL,
  191. VK_MULTIPLY, VK_SUBTRACT, VK_ADD, VK_DIVIDE) should appear after all the other
  192. Virtual Keys. Normally, these keys, with the exception of VK_DCIMAL, do not
  193. need explicit entries anyway: kbdtool will use the defaults (shown above) and
  194. place them in the correct order. VK_DECIMAL is typically either a period "."
  195. or a comma "," and has no default entry. Its entry should be placed at the end
  196. of the LAYOUT section.
  197. Order of entries for duplicated characters.
  198. If the layout contains more than one way to produce a given character, the
  199. way to arrange that VkKeyScanEx reports a particular key combination is to
  200. make sure that all entries containing the given charcter have the same number
  201. of columns, and that the chosen one appears first. For example, the Hungarian
  202. keyboard layout has more than one way to type I acute: the VK_OEM_102 key
  203. has i acute and I acute on it, but you can also type I acute with AltGr+I.
  204. The entry for the "I" key would normally look like this:
  205. 17 I 1 i I 00cd // 0x00cd isI acute
  206. and the entry for the "I acute" key looks like this:
  207. 56 OEM_102 1 00ed 00cd < 001c // i acute, I acute
  208. To ensure that VkKeyScanEx reports Shift+VK_OEM_102 as the key combo for
  209. I acute (0xcd), we must give the "I" key an extra column with with the value -1
  210. (meaning no character), so that both entries have the same number of columns,
  211. and place the preferred one first:
  212. 56 OEM_102 1 00ed 00cd < 001c // i acute, I acute
  213. 17 I 1 i I 00cd -1 // 0x00cd isI acute
  214. By giving both entries the same number of columns, they will appear in the same
  215. subsection of the keyboard layout DLL. VkKeyScan searches within each
  216. subsection in order, but the order in which it searches subsections themselves
  217. is not specified.
  218. The exception to this requirement is when the duplicated character is produced
  219. with Ctrl or Ctrl+Shift - VkKeyScan will report such a key combo only if no
  220. other key combination produces that character.
  221. DEADKEY
  222. =======
  223. There may be many DEADKEY tables in the layout. There should be one for each
  224. dead key that appears in the LAYOUT section.
  225. The format of a standard DEADKEY table is a s follows.
  226. DEADKEY <deadchar> ; Comment
  227. <basechar1> <compchar1> ; comment
  228. <basechar2> <compchar2> ; comment
  229. <basechar3> <compchar3> ; comment
  230. ... ...
  231. <basecharN> <compcharN> ; comment
  232. 0020 <spacing_deadchar>
  233. A DEADKEY table describe how a specified diacritic or "dead" character can
  234. combine with other characters to form a single composite character.
  235. The first line of each DEADKEY section is of the following form:
  236. DEADKEY <deadchar> ; Comment
  237. Where <deadchar> represents the dead character, either in the form of a four
  238. digit hexadecimal number or the character itself (except semicolon).
  239. This is followed by any number of lines of the following form:
  240. <basechar> <compchar>
  241. Where the <basechar> is the base character and <compchar> is the resulting
  242. composite character when the <deadchar> is typed followed by <basechar>.
  243. Dead characters appear in the LAYOUT table as hexadecimal values or characters
  244. with a @ appended. These represent diacritics which may be combined with
  245. other characters to form a single composite character.
  246. Dead chars do not appear when you type them, but combine with the next (base)
  247. character typed to form a single composite character (or two separate characters
  248. if there is no valid way for the dead and base characters to combine).
  249. By convention, Microsoft ships keyboard layouts that encode the spacing version
  250. of the diacritic (if it exists) rather than the non-spacing or combining form.
  251. For example, use 0060 (GRAVE ACCENT) rather than 0300 (COMBINING GRAVE ACCENT).
  252. Using spacing dead characters will cause the dead character to appear as a
  253. spacing character when there is no combination with the base character. Also,
  254. the dead character is sent to the application in a WM_DEADCHAR message at the
  255. time it is typed: most apps ignore this, but for backward compatibility it will
  256. be best to define the deadkey as a spacing character whenever possible.
  257. When chosing the best spacing version of a diacritic, try to pick one that is
  258. most likely to be found in many fonts, as well most likely to be translated by
  259. the NLS subsystem into as many different ANSI codepages as possible.
  260. For example, choose 0027 (Apostrophe) as the dead character value for 030d
  261. (Combining Line Above) instead of 0384 (Greek Tonos) or 02c8 (Modifier Letter
  262. Vertical Line Above), since Apostrophe it is present in most fonts, and the NLS
  263. API will be able to convert the Unicode Apostrophe into many different ANSI
  264. codepages so that ANSI apps will work well with the keyboardf layout. If you
  265. 030d itself as the dead character, an ANSI app would receive question marks
  266. instead of the uncomposed 030d unless it happened to be running in the Greek
  267. input locale, since the NLS API can only translate 030d to an ANSI character
  268. (0xb4) in the Greek codepage (1253).
  269. The results of a composition is usually a spacing character but it can also be
  270. another dead character. This is achieved by including lines such as:
  271. <basechar> <compchar>@
  272. which is useful if you want to produce a single composite character with
  273. multiple diacritics, such as Acute + Acute + u giving u with double acute,
  274. which could be implemented by the following two tables.
  275. eg:
  276. DEADKEY 00b4 ; combinations with Acute
  277. 00b4 02ba@ ; Acute + Acute -> Double Acute (Modifier Letter Double Prime)
  278. 0020 00b4 ; Acute + Space -> Acute
  279. DEADKEY 02ba ; combinations with Double Acute (Modifier Letter Double Prime)
  280. u 0171 ; Double Acute + u -> Small Letter u With Double Acute
  281. U 0170 ; Double Acute + u -> Capital Letter U With Double Acute
  282. 0020 2033 ; Double Acute + space -> Double Prime
  283. By convention, the last line of every DEADKEY table should be a line composing
  284. the deadkey with SPACE. Standard keyboard behavior is to have all dead keys
  285. compose with space to form a spacing representation of that dead character.
  286. KEYNAME
  287. =======
  288. This is a table of scancodes of certain keys and the user-readable names for
  289. those keys as returned by the GetKeyNameText API.
  290. The syntax is 0 or more lines of the form:
  291. <scancode> <name>
  292. Where <scancode> is 2 hexadecimal digits, and <name> is either a single word
  293. optionally enclosed in quotes, or multiple words enclosed in quotes.
  294. The keys listed in this section are those that do not have an 0xE0 prefixed
  295. scancode, and which do not produce normally an alpha-numeric character.
  296. Examples are Backspace, Enter, Ctrl, etc.
  297. The names are typically in the language that the keyboard supports, or English.
  298. KEYNAME_EXT
  299. ===========
  300. The same as the KEYNAME section (above) but for keys that do have the 0xE0
  301. scancode prefix.
  302. KEYNAME_DEAD
  303. ============
  304. Similar to the KEYNAME and KEYNAME_EXT sections, this provides names for keys
  305. that produce dead characters.
  306. The syntax is 0 or more lines of the form:
  307. <unicode> <name>
  308. where <unicode> is 4 hex digits representing the Unicode value of the character.
  309. This character must appear elsewhere in the LAYOUT section as a dead key, and
  310. should also have a DEADKEY table.
  311. The <name> is the same format as the <name> in the KEYNAME and KEYNAME_EXT
  312. sections.
  313. The KEYNAME_DEAD section need only be present if dead characters are present
  314. in the keyboard layout.
  315. ENDKBD
  316. ======
  317. Signifies the end of the keyboard layout definition.
  318. The syntax is simple the keyword ENDKBD appearing by itself on the last line.
  319. Any lines following this are ignored.