~ubuntu-branches/debian/lenny/fpc/lenny

« back to all changes in this revision

Viewing changes to fpcsrc/rtl/os2/kbdcalls.pas

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-05-17 17:12:11 UTC
  • mfrom: (3.1.9 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080517171211-9qi33xhd9evfa0kg
Tags: 2.2.0-dfsg1-9
[ Torsten Werner ]
* Add Mazen Neifer to Uploaders field.

[ Mazen Neifer ]
* Moved FPC sources into a version dependent directory from /usr/share/fpcsrc
  to /usr/share/fpcsrc/${FPCVERSION}. This allow installing more than on FPC
  release.
* Fixed far call issue in compiler preventing building huge binearies.
  (closes: #477743)
* Updated building dependencies, recomennded and suggested packages.
* Moved fppkg to fp-utils as it is just a helper tool and is not required by
  compiler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{Set tabsize to 4.}
 
2
{****************************************************************************
 
3
 
 
4
 
 
5
                           KBDCALLS interface unit
 
6
                     Free Pascal Runtime Library for OS/2
 
7
                   Copyright (c) 1999-2000 by Florian Kl�mpfl
 
8
                    Copyright (c) 1999-2000 by Daniel Mantione
 
9
                      Copyright (c) 1999-2000 by Tomas Hajny
 
10
 
 
11
 The Free Pascal runtime library is distributed under the Library GNU Public
 
12
 License v2. So is this unit. The Library GNU Public License requires you to
 
13
 distribute the source code of this unit with any product that uses it.
 
14
 Because the EMX library isn't under the LGPL, we grant you an exception to
 
15
 this, and that is, when you compile a program with the Free Pascal Compiler,
 
16
 you do not need to ship source code with that program, AS LONG AS YOU ARE
 
17
 USING UNMODIFIED CODE! If you modify this code, you MUST change the next
 
18
 line:
 
19
 
 
20
 <This is an official, unmodified Free Pascal source code file.>
 
21
 
 
22
 Send us your modified files, we can work together if you want!
 
23
 
 
24
 Free Pascal is distributed in the hope that it will be useful,
 
25
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 
26
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
27
 Library GNU General Public License for more details.
 
28
 
 
29
 You should have received a copy of the Library GNU General Public License
 
30
 along with Free Pascal; see the file COPYING.LIB.  If not, write to
 
31
 the Free Software Foundation, 59 Temple Place - Suite 330,
 
32
 Boston, MA 02111-1307, USA.
 
33
 
 
34
****************************************************************************}
 
35
 
 
36
unit KbdCalls;
 
37
 
 
38
{ Interface library to KBDCALLS.DLL (through EMXWRAP.DLL)
 
39
 
 
40
Variant records and aliases for some record types created to maintain highest
 
41
possible level of compatibility with other existing OS/2 compilers.
 
42
 
 
43
Changelog:
 
44
 
 
45
    People:
 
46
 
 
47
        TH - Tomas Hajny (xhajt03@mbox.vol.cz on Internet)
 
48
 
 
49
    Date:           Description of change:              Changed by:
 
50
 
 
51
     -              First released version 1.0          TH
 
52
 
 
53
Coding style:
 
54
 
 
55
    I have tried to use the same coding style as Daniel Mantione in unit
 
56
    DOSCALLS, although I can't say I would write it the same way otherwise
 
57
    (I would write much more spaces myself, at least). Try to use it as well,
 
58
    please. Original note by Daniel Mantione follows:
 
59
 
 
60
 
 
61
    It may be well possible that coding style feels a bit strange to you.
 
62
    Nevertheless I friendly ask you to try to make your changes not look all
 
63
    to different. To make life easier, set your IDE to use tab characters,
 
64
    turn optimal fill, autoindent and backspace unindents on and set a
 
65
    tabsize of 4.}
 
66
 
 
67
{***************************************************************************}
 
68
interface
 
69
{***************************************************************************}
 
70
 
 
71
{$IFDEF FPC}
 
72
    {$PACKRECORDS 1}
 
73
{$ENDIF FPC}
 
74
 
 
75
const
 
76
{return codes / error constants (those marked with * shouldn't occur under
 
77
normal conditions)}
 
78
    No_Error                        =  0;
 
79
    Error_Invalid_Parameter         = 87;
 
80
    Error_Sem_TimeOut               =121;
 
81
    Error_Kbd_Parameter             =373;
 
82
    Error_Kbd_No_Device             =374; {*}
 
83
    Error_Kbd_Invalid_IOWait        =375; {*}
 
84
    Error_Kbd_Invalid_Length        =376;
 
85
    Error_Kbd_Invalid_Echo_Mask     =377;
 
86
    Error_Kbd_Invalid_Input_Mask    =378;
 
87
    Error_Kbd_Smg_Only              =407; {*}
 
88
    Error_Kbd_Invalid_ASCIIZ        =408;
 
89
    Error_Kbd_Invalid_Mask          =409;
 
90
    Error_Kbd_Register              =410;
 
91
    Error_Kbd_Deregister            =411;
 
92
    Error_Kbd_Invalid_Handle        =439;
 
93
    Error_Kbd_No_more_Handle        =440;
 
94
    Error_Kbd_Cannot_Create_KCB     =441;
 
95
    Error_Kbd_Codepage_Load_Incompl =442; {*}
 
96
    Error_Kbd_Invalid_CodePage_ID   =443; {*}
 
97
    Error_Kbd_No_CodePage_Support   =444; {*}
 
98
    Error_Kbd_Focus_Required        =445;
 
99
    Error_Kbd_Focus_Already_Active  =446; {*}
 
100
    Error_Kbd_Keyboard_Busy         =447;
 
101
    Error_Kbd_Invalid_CodePage      =448;
 
102
    Error_Kbd_Unable_To_Focus       =449; {*}
 
103
    Error_Kbd_Detached              =464;
 
104
    Error_Kbd_No_Console            =500; {*}
 
105
    Error_Kbd_Extended_SG           =504;
 
106
 
 
107
{FnMask}
 
108
    kr_KbdCharIn        =$00000001;
 
109
    kr_KbdPeek          =$00000002;
 
110
    kr_KbdFlushBuffer   =$00000004;
 
111
    kr_KbdGetStatus     =$00000008;
 
112
    kr_KbdSetStatus     =$00000010;
 
113
    kr_KbdStringIn      =$00000020;
 
114
    kr_KbdOpen          =$00000040;
 
115
    kr_KbdClose         =$00000080;
 
116
    kr_KbdGetFocus      =$00000100;
 
117
    kr_KbdFreeFocus     =$00000200;
 
118
    kr_KbdGetCP         =$00000400;
 
119
    kr_KbdSetCP         =$00000800;
 
120
    kr_KbdXLate         =$00001000;
 
121
    kr_KbdSetCustXT     =$00002000;
 
122
 
 
123
{WaitFlag}
 
124
    IO_Wait     =0;
 
125
        {KbdCharIn: wait for a character if one is not available}
 
126
        {KbdGetFocus: wait for the focus}
 
127
        {KbdStringIn: in binary input mode, wait until CharBuf is full, in    }
 
128
        {             ASCII input mode wait until a carriage return is pressed}
 
129
    IO_NoWait   =1;
 
130
        {KbdCharIn: immediate return if no character is available}
 
131
        {KbdGetFocus: do not wait for the focus}
 
132
        {KbdStringIn: send an immediate return if no characters are available,}
 
133
        {             if characters available, send them (up to the maximum   }
 
134
        {             length); not supported in ASCII input mode              }
 
135
 
 
136
{TKbdInfo.fsMask}
 
137
    Keyboard_Echo_On            =$0001; {echo is on}
 
138
    Keyboard_Echo_Off           =$0002; {echo is off}
 
139
    Keyboard_Binary_Mode        =$0004; {binary mode is on}
 
140
    Keyboard_ASCII_Mode         =$0008; {ASCII mode is on}
 
141
    Keyboard_Modify_State       =$0010; {shift state is modified}
 
142
    Keyboard_Modify_Interim     =$0020; {interim character flags are modified}
 
143
    Keyboard_Modify_TurnAround  =$0040; {turn-around character is modified}
 
144
    Keyboard_2B_TurnAround      =$0080; {length of the turn-around character  }
 
145
                                        {(meaningful only if                  }
 
146
                                        {Keyboard_Modify_TurnAround bit is on)}
 
147
    Keyboard_Shift_Report       =$0100; {shift return is on}
 
148
 
 
149
{TKbdInfo.fsState/TKbdKeyInfo.fsState/TKbdTrans.fsState}
 
150
    KbdStF_RightShift           =$0001;
 
151
    KbdStF_LeftShift            =$0002;
 
152
    KbdStF_Control              =$0004;
 
153
    KbdStF_Alt                  =$0008;
 
154
    KbdStF_ScrollLock_On        =$0010;
 
155
    KbdStF_Numlock_On           =$0020;
 
156
    KbdStF_Capslock_On          =$0040;
 
157
    KbdStF_Insert_On            =$0080;
 
158
    KbdStF_LeftControl          =$0100;
 
159
    KbdStF_LeftAlt              =$0200;
 
160
    KbdStF_RightControl         =$0400;
 
161
    KbdStF_RightAlt             =$0800;
 
162
    KbdStF_ScrollLock           =$1000;
 
163
    KbdStF_NumLock              =$2000;
 
164
    KbdStF_CapsLock             =$4000;
 
165
    KbdStF_SysReq               =$8000;
 
166
 
 
167
{TKbdTrans.fbStatus}
 
168
    KbdTrF_Shift_Key_In         =$01;   {shift status returned}
 
169
                                        {without character    }
 
170
    KbdTrF_Extended_Key_In      =$02;   {extended key code }
 
171
                                        {from the keyboard,}
 
172
                                        {not a character   }
 
173
    KbdTrF_Conversion_Request   =$20;   {immediate conversion}
 
174
                                        {requested           }
 
175
    KbdTrF_Final_Char_In        =$40;   {either $40 or $80 or both}
 
176
    KbdTrF_Interim_Char_In      =$80;   {must be present          }
 
177
 
 
178
{TKbdHWID.idKbd}
 
179
    Keyboard_Undetermined   =$0000; {undetermined keyboard type}
 
180
    Keyboard_AT_Compatible  =$0001; {PC-AT Standard Keyboard}
 
181
    Keyboard_Enhanced_101   =$AB41; {101 Key Enhanced Keyboard}
 
182
    Keyboard_Enhanced_102   =$AB41; {102 Key Enhanced Keyboard}
 
183
    Keyboard_Enhanced_88_89 =$AB54; {88 and 89 Key Enhanced Keyboards}
 
184
    Keyboard_Enhanced_122   =$AB85; {122 Key Enhanced Keyboard}
 
185
    Keyboard_AT_Compatable=Keyboard_AT_Compatible;
 
186
    Keyboard_SpaceSaver=Keyboard_Enhanced_88_89;
 
187
 
 
188
 
 
189
type
 
190
{TKbdKeyInfo - record type for character data for KbdCharIn and KbdPeek}
 
191
(*   #pragma pack(2) ??? *)
 
192
    TKbdKeyInfo=record
 
193
        chChar:char;    {ASCII character code; the scan code received}
 
194
                        {from the keyboard is translated to the ASCII}
 
195
                        {character code                              }
 
196
        case boolean of
 
197
        false:(
 
198
        chScan:byte;    {scan Code received from the keyboard}
 
199
        fbStatus:byte;  {state of the keystroke event, see KbdTrF_* constants}
 
200
        bNlsShift:byte; {NLS shift status (always 0?)}
 
201
        fsState:word;   {shift key status, see KbdStF_* constants}
 
202
        Time:cardinal); {time stamp indicating when a key was pressed,}
 
203
                        {specified in milliseconds from the time      }
 
204
                        {the system was started                       }
 
205
        true:(
 
206
        chScan2:char;   (* should be chScan, fbStatus and bNlsShift,   *)
 
207
        fbStatus2:byte; (* but this construct is unsupported currently *)
 
208
        bNlsShift2:char);
 
209
    end;
 
210
    PKbdKeyInfo=^TKbdKeyInfo;
 
211
    KbdKeyInfo=TKbdKeyInfo; {for better compatibility with other compilers}
 
212
 
 
213
{record type for KbdStringIn}
 
214
    TStringInBuf=record
 
215
        cb:word;    {length of the input buffer, maximum length is 255}
 
216
        cchIn:word; {number of bytes actually read into the buffer}
 
217
    end;
 
218
    PStringInBuf=^TStringInBuf;
 
219
    StringInBuf=TStringInBuf;
 
220
 
 
221
{TKbdInfo record type, for KbdSet/GetStatus}
 
222
    TKbdInfo=record
 
223
        cb,             {total length in bytes, 10 is the only valid value  }
 
224
        fsMask,         {see TKbdInfo.fsMask constants, higher bits reserved}
 
225
                        {and set to 0                                       }
 
226
        chTurnAround,   {definition of the turn-around character, in ASCII   }
 
227
                        {and extended-ASCII format, the turn-around character}
 
228
                        {is defined as the carriage return, in ASCII format  }
 
229
                        {only, the turn-around character is defined in the   }
 
230
                        {low-order byte; usually $000D                                }
 
231
        fsInterim,      {interim character flags: bits 0-4 and 6 - reserved   }
 
232
                        {                                        and set to 0,}
 
233
                        {                         bit 5          - application}
 
234
                        {                                        requested    }
 
235
                        {                                        immediate    }
 
236
                        {                                        conversion   }
 
237
                        {                         bit 7          - interim    }
 
238
                        {                                        character    }
 
239
                        {                                        flag is on   }
 
240
                        {                         bits 8-15      - NLS shift  }
 
241
                        {                                        state        }
 
242
        fsState:word;   {shift state, see TKbdInfo.fsState constants}
 
243
    end;
 
244
    PKbdInfo=^TKbdInfo;
 
245
    KbdInfo=TKbdInfo;
 
246
 
 
247
{record type for KbdGetHWID}
 
248
    TKbdHWID=record
 
249
        cb,                 {length in bytes, on input length of the TKbdHWID}
 
250
                            {record (at least 2), on output the actual number}
 
251
                            {of bytes returned                               }
 
252
        idKbd,              {keyboard type: $0000 = undetermined keyboard type}
 
253
                            {               $0001 = PC-AT Standard Keyboard   }
 
254
                            {               $AB41 = 101 Key Enhanced Keyboard }
 
255
                            {               $AB41 = 102 Key Enhanced Keyboard }
 
256
                            {               $AB54 = 88 and 89 Key Enhanced    }
 
257
                            {                        Keyboards                }
 
258
                            {               $AB85 = 122 Key Enhanced Keyboard }
 
259
                            {- see Keyboard_* constants                       }
 
260
        usReserved1,        {reserved, returned set to zero (secondary ID?)}
 
261
        usReserved2:word;   {reserved, returned set to zero}
 
262
    end;
 
263
    PKbdHWID=^TKbdHWID;
 
264
    KbdHWID=TKbdHWID;
 
265
 
 
266
{record type for KbdXlate}
 
267
(*   #pragma pack(2) ???*)
 
268
    TKbdTrans=record
 
269
        case boolean of
 
270
        false:(
 
271
            CharData:TKbdKeyInfo);
 
272
        true:(
 
273
            chChar:char;    {ASCII character code; the scan code received}
 
274
                            {from the keyboard is translated to the ASCII}
 
275
                            {character code                              }
 
276
            case boolean of
 
277
            false:(
 
278
            chScan,         {scan Code received from the keyboard}
 
279
            fbStatus,       {state of the keystroke event,}
 
280
                            {see KbdTrF_* constants       }
 
281
            bNlsShift:byte; {NLS shift status (always 0?)}
 
282
            fsState:word;   {shift key status, see KbdStF_* constants}
 
283
            Time:cardinal;  {time stamp indicating when a key was pressed,}
 
284
                            {specified in milliseconds from the time      }
 
285
                            {the system was started                       }
 
286
            fsDD:word;      {device driver returned flag, }
 
287
                            {see KbdDDFlagWord notes below}
 
288
            fsXlate:word;   {translation flag: 0 - translation incomplete,}
 
289
                            {                  1 - translation complete   }
 
290
            fsShift:word;   {identifies the state of translation across    }
 
291
                            {successive calls, initially the value should  }
 
292
                            {be zero; it may take several calls to this    }
 
293
                            {function to complete a character, the value   }
 
294
                            {should not be changed unless a new translation}
 
295
                            {is required (that is, reset value to zero)    }
 
296
            sZero:word);    {reserved, set to 0}
 
297
            true:(
 
298
            chScan2,        (* should be chScan, fbStatus and bNlsShift,   *)
 
299
            fbStatus2,      (* but this construct is unsupported currently *)
 
300
            bNlsShift2:char));
 
301
    end;
 
302
    PKbdTrans=^TKbdTrans;
 
303
    KbdTrans=TKbdTrans;
 
304
 
 
305
{KbdDDFlagWord notes:
 
306
  bits 15-14    Available. These bits are available for communication between
 
307
                monitors; they are not used by the physical device driver. The
 
308
                monitor applications coordinate the use of these flags.
 
309
  Bits 13-10    Reserved, set to zero. Monitors must pass these flags as is.
 
310
                They must set these flags to 0 in packets they create.
 
311
  Bit 9         Accented. This key is translated using the previous key passed,
 
312
                which is an accent key. Where an accent key is pressed, and the
 
313
                following key does not use the accent, a packet containing the
 
314
                accent character itself is first passed with this bit set. The
 
315
                scan code field of MonFlagWord (see above) would be 0,
 
316
                indicating a non-key generated record. A valid packet
 
317
                containing that following keystroke is then passed without this
 
318
                bit set.
 
319
  Bit 8         Multimake. The translation process sees this scan code as
 
320
                a typematic repeat of a toggle key or a shift key. Because
 
321
                toggle and shift keys only change state on the first make after
 
322
                each key-break, no state information is changed. For example,
 
323
                the NumLock toggle bit in the shift status word is not changed,
 
324
                even though this can be the NumLock key. If this key is a valid
 
325
                character, it does not go into the Keyboard Input Buffer (KIB)
 
326
                once this bit is set.
 
327
  Bit 7         Secondary. The scan code prior to the one in this packet was
 
328
                the Secondary Key Prefix (see below).
 
329
  Bit 6         Key break. This record is generated by the release (the break)
 
330
                of the key involved.
 
331
  Bits 5-0      Key type. This numeric field flags the physical device driver
 
332
                and reports that this is a key that requires action. The number
 
333
                in this field is filled in during the translation of the scan
 
334
                code. The value allows the driver to act on keystrokes without
 
335
                regard for what scan codes the keyboard uses or character codes
 
336
                that the current translation process may be using. The
 
337
                following values are currently defined:
 
338
 
 
339
                  -  Value for keys that are always placed in the KIB.
 
340
                     Zero = no special action, always place in KIB.
 
341
 
 
342
                  -  Values acted on prior to passing packet to monitors.
 
343
                     Except for the final keystroke of the DUMP key sequences,
 
344
                     all of these values are passed on to the monitors. They
 
345
                     are not placed in the KIB. The XlatedChar and XlatedScan
 
346
                     fields are undefined for these values:
 
347
                     01h    ACK. This scan code is a keyboard acknowledge.
 
348
                            Personal Computer IBM* AT* attached keyboards
 
349
                            set this value on an FAh scan code.
 
350
                     02h    Secondary key prefix. This scan code is a prefix
 
351
                            generated by the Enhanced Keyboard. It indicates
 
352
                            that the next scan code coming is one of the
 
353
                            secondary keys that exists on that keyboard.
 
354
                            Usually set on an E0h scan code or an E1h scan
 
355
                            code.
 
356
                     03h    Kbd overrun. This scan code is an overrun
 
357
                            indication from the keyboard. On an IBM Personal
 
358
                            Computer AT-attached keyboard, this value would be
 
359
                            set on an FFh scan code.
 
360
                     04h    Resend. This scan code is a resend request from the
 
361
                            keyboard. On an IBM Personal Computer AT-attached
 
362
                            keyboard, this value would be set on an FEh scan
 
363
                            code.
 
364
                     05h    Reboot key. This scan code completes the multi-key
 
365
                            restart sequence. On an IBM Personal Computer AT
 
366
                            attached-keyboard, this value would be used when
 
367
                            the Ctrl+Alt+Delete sequence is used.
 
368
                     06h    Dump key. This scan code completes the multi-key
 
369
                            Stand Alone Dump request sequence. On an IBM
 
370
                            Personal Computer AT-attached keyboard, this value
 
371
                            would be used on completion of the second
 
372
                            consecutive press of Ctrl+Alt+NumLock or
 
373
                            Ctrl+Alt+F10 without other keystrokes between the
 
374
                            two presses.
 
375
                     07h-
 
376
                     0Ah    See entries below.
 
377
 
 
378
                     0Bh    Invalid accent combination. This scan code follows
 
379
                            an accent scan code but the combination is not
 
380
                            valid, and neither key is put in the KIB.
 
381
                            (Note: This is set if the Canadian-French code
 
382
                            pages are in use.)
 
383
                     0Ch    System-defined hot keys.
 
384
                     0Dh
 
385
                     -0Fh   Reserved. Treated as undefined. See entry 3Fh.
 
386
                  -  Values acted on after passing packet to monitors. Except
 
387
                     where noted, these values are placed in the KIB when the
 
388
                     physical device driver is in binary mode; they are not
 
389
                     placed in the KIB when the physical device driver is in
 
390
                     ASCII mode. (Also listed are those that never get placed
 
391
                     in the KIB.)
 
392
                     07h    Shift key. This scan code translates as a shift key
 
393
                            and affects the shift status fields of the CharData
 
394
                            record, but does not generate a defined character.
 
395
                            It is not placed in the KIB. The XlatedChar field
 
396
                            is undefined. The scan code field is 0.
 
397
                     08h    Pause key. This scan code is translated as the key
 
398
                            sequence meaning pause. On an IBM Personal Computer
 
399
                            AT-attached keyboard, this value is used when the
 
400
                            Ctrl+NumLock sequence is used. The key itself is
 
401
                            not placed in the KIB.
 
402
                     09h    Pseudo-Pause key. This scan code is translated into
 
403
                            the value that is treated as the Pause key when the
 
404
                            physical device driver is in ASCII mode. On most
 
405
                            keyboards, this would be when the Ctrl+S
 
406
                            combination is used. The key itself is not placed
 
407
                            in the KIB.
 
408
                     0Ah    Wake-up key. This scan code follows a Pause key or
 
409
                            Pseudo-Pause key, which causes the Pause state to
 
410
                            end. The key itself is not placed in the KIB.
 
411
                     10h    Accent key. This scan code is translated and used
 
412
                            as a key to alter the translation of the next key
 
413
                            to come in. The packet containing this value is
 
414
                            passed when the accent key is pressed, but it is
 
415
                            not put into the KIB, unless the Accented bit is
 
416
                            ON. The next key determines this decision. If the
 
417
                            next key is one that can be accented, then it is
 
418
                            passed by itself with the Accented bit ON. If that
 
419
                            next key cannot be accented by this accent, then
 
420
                            two packets are passed. The first contains the
 
421
                            character to print for the accent itself. It has
 
422
                            the Accent key value and the Accented flag (which
 
423
                            allows the packet to be put in the KIB). The second
 
424
                            packet contains a regular translation of that
 
425
                            following key.
 
426
                            (Note: The two packets get passed for every
 
427
                            language except Canadian-French - see entry 0Bh.)
 
428
                     11h    Break key. This scan code is translated as the key
 
429
                            sequence meaning break. On the IBM Personal
 
430
                            Computer AT-attached keyboard, this value is used
 
431
                            where the Ctrl+Break sequence is used.
 
432
                     12h    Pseudo-Break key. This scan code is translated into
 
433
                            the value that is treated as the Break key when the
 
434
                            physical device driver is in ASCII mode. On most
 
435
                            keyboards, this would be when the Ctrl+C
 
436
                            combination is used. Notice that the event
 
437
                            generated by this key is separate from the one
 
438
                            generated by the Break key when in the binary mode.
 
439
                     13h    Print Screen key. This scan code is translated as
 
440
                            the key sequence meaning Print Screen. On an IBM
 
441
                            Personal Computer AT-attached keyboard, this value
 
442
                            is used where the Shift+PrtSc sequence is used.
 
443
                     14h    Print Echo key. This scan code is translated as the
 
444
                            key sequence meaning Print Echo. This value is used
 
445
                            where the Ctrl+PrtSc sequence is used.
 
446
                     15h    Pseudo-Print Echo key. This scan code is translated
 
447
                            into the value that is treated as the Print Echo
 
448
                            key when the physical device driver is in ASCII
 
449
                            mode. On most keyboards, this would show as the
 
450
                            Ctrl+P combination.
 
451
                     16h    Print-Flush key. This scan code is translated into
 
452
                            the key sequence Print-Flush. This value is used
 
453
                            where the Ctrl+Alt+PrtSc sequence is used.
 
454
                     17h
 
455
                     -2Fh   Reserved, set to zero. Treated as undefined. See
 
456
                            entry 3Fh.
 
457
                  -  Values for packets not generated by a keystroke:
 
458
                     30h
 
459
                     -37h   Reserved.
 
460
                     38h
 
461
                     -3Eh   Reserved. Treated as undefined. See entry 3Fh.
 
462
                  -  Value for keys the translation process does not recognize:
 
463
                     3Fh    Undefined. This scan code, or its combination with
 
464
                            the current shift state, is not recognized in the
 
465
                            translation process.
 
466
}
 
467
 
 
468
{header of TXLateTbl}
 
469
    TXHeader=record
 
470
        XTableID:word;      {code page number}
 
471
        XTableFlags1:word;  {bits 0-2 determine which shift key or key      }
 
472
                            {combination affects Char3 of each TXLateKeyDef }
 
473
                            {element, bits 7-10 determine which shift key or}
 
474
                            {key combination causes Char5 to be used in each}
 
475
                            {TXLateKeyDef element                           }
 
476
                            {bit 0 - ShiftAlt (use Shift+Alt instead of     }
 
477
                            {           Ctrl+Alt)                           }
 
478
                            {bit 1 - AltGrafL (use left Alt key as          }
 
479
                            {           Alt+Graphics)                       }
 
480
                            {bit 2 - AltGrafR (use right Alt key as         }
 
481
                            {           Alt+Graphics)                       }
 
482
                            {bit 3 - ShiftLock (treat Caps Lock as          }
 
483
                            {           ShiftLock)                          }
 
484
                            {bit 4 - DefaultTable (default table for the    }
 
485
                            {           language)                           }
 
486
                            {bit 5 - ShiftToggle (1 = toggle ShiftLock,     }
 
487
                            {           0 = latch it)                       }
 
488
                            {bit 6 - AccentPass (pass accent and non-accent }
 
489
                            {           key through; 1 = pass on accent keys}
 
490
                            {           and beep, 0 = beep only             }
 
491
                            {bit 7 - CapsShift (Caps+Shift uses Char5)      }
 
492
                            {bit 8 - MachDep (machine-dependent table)      }
 
493
                            {bits  9-10 reserved                            }
 
494
                            {bits 11-15 reserved                            }
 
495
        XTableFlags2:word;  {reserved, set to zero}
 
496
        KbdType:word;       {keyboard type, 1 for extended (all common types)}
 
497
        KbdSubType:word;    {reserved}
 
498
        XtableLen:word;     {length of table}
 
499
        EntryCount:word;    {number of KeyDef entries}
 
500
        EntryWidth:word;    {width of KeyDef entries}
 
501
        Country:word;       {language ID}
 
502
        TableTypeID:word;   {the table type; 1st byte (type):     01X 00X     }
 
503
                            {                2nd byte (sub-type): 00X reserved}
 
504
        SubCountryID:cardinal;
 
505
                            {sub-language identifier}
 
506
        Reserved:array[1..8] of word;
 
507
    end;
 
508
    PXHeader=^TXHeader;
 
509
 
 
510
{element of TXLateTbl, not all entries are used (unused entries are zero)}
 
511
    TXLateKeyDef=record
 
512
        XlateOp:word;   {translate operation specifier;             }
 
513
                        {bits 0- 6 - AccentFlags (see Notes 1 and 8)}
 
514
                        {bits 7-15 - KeyType (see Note 2)           }
 
515
        Char1:char;
 
516
        Char2:char;
 
517
        Char3:char;
 
518
        Char4:char;
 
519
        Char5:char;
 
520
    end;
 
521
    PXLateKeyDef=^TXLateKeyDef;
 
522
 
 
523
{record type for character definition in TAccentEntry}
 
524
    TKeyCode=record
 
525
        CharCode:char;
 
526
        ScanCode:byte;
 
527
    end;
 
528
 
 
529
{accent entry definitions for TAccentTable, see Notes 1 and 9}
 
530
    TAccentEntry=record
 
531
        NonAccent:TKeyCode;             {char/scan code when}
 
532
                                        {not used as accent }
 
533
        CtlAccent:TKeyCode;             {char/scan code when}
 
534
                                        {used with Ctrl key }
 
535
        AltAccent:TKeyCode;             {char/scan code when}
 
536
                                        {used with Alt key  }
 
537
        Maps:array[1..20] of TKeyCode;  {from char-to-char for translation}
 
538
    end;
 
539
    PAccentEntry=^TAccentEntry;
 
540
 
 
541
{table of accent key definitions for TXLateTbl}
 
542
    TAccentTable=array[1..7] of TAccentEntry;
 
543
    PAccentTable=^TAccentTable;
 
544
 
 
545
{record type for SetCustXT, one element for each possible scan code
 
546
(entries are in scan code order, based on the remapped scan codes
 
547
returned by the keyboard controller)}
 
548
    TXLateTbl=record
 
549
        XHeader:TXHeader;
 
550
        KeyDefs:array [1..127] of TXLateKeyDef;
 
551
        AccentTbl:TAccentTable;
 
552
    end;
 
553
    PXLateTbl=^TXLateTbl;
 
554
 
 
555
{Remarks for TXLateTbl record type:
 
556
 
 
557
  The request changes the device driver resident code page for the system
 
558
  and updates the zero entry of the Code Page Control Block.
 
559
 
 
560
* Note 1
 
561
  The AccentFlags field of the KeyDef record has seven flags that are
 
562
  individually set if a corresponding entry in the accent table applies to this
 
563
  scan code. If the key pressed immediately before the current one was an
 
564
  accent key and the bit for that accent is set in the AccentFlags field for
 
565
  the current key, the corresponding AccentTable entry is searched for the
 
566
  replacement character value to use.  If no replacement is found and bit 6 of
 
567
  the XlateFlags1 field is set, the not-an-accent beep is sounded and the
 
568
  accent character and current character are passed as two separate
 
569
  characters.  Also see Note 8.
 
570
 
 
571
* Note 2
 
572
 
 
573
  The KeyType field of the KeyDef record currently has the following values
 
574
  defined. The remaining values up to 1Fh are undefined. The effect of each
 
575
  type of shift is defined below. Except where otherwise noted, when no
 
576
  shifts are active, Char1 is the translated character. (See Note 3.) Notice
 
577
  that any of the Alt, Alt+Char, Alt+Shift, or Alt+Gr keys (or all of them) can
 
578
  be present on a keyboard based on the AltGrafL and AltGrafR bits in the
 
579
  XTableFlags1 flag word in the table header.
 
580
 
 
581
  01h   AlphaKey. Alphabetical character key:
 
582
 
 
583
        Shift            Uses Char2. If Caps Lock, uses Char1.
 
584
        Caps Lock        Uses Char2. If Shift, uses Char1.
 
585
        Ctrl             Set standard control code for this key's Char1 value.
 
586
                         See Note 4.
 
587
        Alt              Standard extended code.  See Note 7.
 
588
        Alt+Char         Uses Char3, if it is not 0.
 
589
        Alt+Shift        Uses Char3, if it is not 0.
 
590
        Alt+Gr           Uses Char3, if it is not 0.
 
591
 
 
592
  02h   SpecKey. Special nonalphabetic character key, no Caps Lock or Alt:
 
593
 
 
594
        Shift            Uses Char2.
 
595
        Caps Lock        No effect, only depends on Shift, or Ctrl.
 
596
        Ctrl             See Note 4.
 
597
        Alt              Marked undefined.
 
598
        Alt+Char         Uses Char3, if it is not 0.
 
599
        Alt+Shift        Uses Char3, if it is not 0.
 
600
        Alt+Gr           Uses Char3, if it is not 0.
 
601
 
 
602
  03h   SpecKeyC. Special nonalphabetic character key with Caps Lock. See
 
603
        Note 15.
 
604
 
 
605
        Shift            Uses Char2. If Caps Lock, uses Char1.
 
606
        Caps Lock        Uses Char2. If Shift, uses Char1.
 
607
        Ctrl             See Note 4.
 
608
        Alt              Uses Char4, if not zero.  See Note 7.
 
609
        Alt+Char         Uses Char3, if it is not 0.
 
610
        Alt+Shift        Uses Char3, if it is not 0.
 
611
        Alt+Gr           Uses Char3, if it is not 0.
 
612
 
 
613
  04h   SpecKeyA. Special nonalphabetic character key with Alt (no Caps
 
614
        Lock):
 
615
 
 
616
        Shift            Uses Char2.
 
617
        Caps Lock        No effect; depends on Shift, Ctrl, or Alt only.
 
618
        Ctrl             See Notes 5 and 9.
 
619
        Alt              See Notes 7 and 10.
 
620
        Alt+Char         Uses Char3, if it is not 0.
 
621
        Alt+Shift        Uses Char3, if it is not 0.
 
622
        Alt+Gr           Uses Char3, if it is not 0.
 
623
 
 
624
  05h   SpecKeyCA. Special nonalphabetic character key with Caps Lock and
 
625
        Alt:
 
626
 
 
627
        Shift            Uses Char2. If Caps Lock, uses Char1.
 
628
        Caps Lock        Uses Char2. If Shift, uses Char1.
 
629
        Ctrl             See Note 4.
 
630
        Alt              See Note 7.
 
631
        Alt+Char         Uses Char3, if it is not 0.
 
632
        Alt+Shift        Uses Char3, if it is not 0.
 
633
        Alt+Gr           Uses Char3, if it is not 0.
 
634
 
 
635
  06h   FuncKey. Function keys. Char1 = n in Fn; Char2 ignored. Sets
 
636
        extended codes 58+Char1, if no shift; if F11 or F12, uses 139 and 140.
 
637
 
 
638
        Shift            Sets extended codes 83+Char1. F11 and F12 use 141
 
639
                         and 142, respectively.
 
640
        Caps Lock        No effect on function keys.
 
641
        Ctrl             Sets extended codes 93+Char1. F11 and F12 use 143
 
642
                         and 144, respectively.
 
643
        Alt              Sets extended codes 103+Char1. F11 and F12 use 145
 
644
                         and 146, respectively.
 
645
        Alt+Char         Uses Char3, if it is not 0.
 
646
        Alt+Shift        Uses Char3, if it is not 0.
 
647
        Alt+Gr           Uses Char3, if it is not 0.
 
648
 
 
649
  07h   PadKey. Keypad keys (see Note 5 for definition of Char1). Note that
 
650
        nonshifted use of these keys is fixed to the extended codes:
 
651
 
 
652
        Shift            Uses Char2, unless Num Lock. See Note 5.
 
653
        Caps Lock        No effect on pad keys, unless Num Lock. See Note 5.
 
654
        Ctrl             Sets extended codes. See Note 5.
 
655
        Alt              Used to build a character. See Note 5.
 
656
        Alt+Char         Uses Char3, if it is not 0.
 
657
        Alt+Shift        Uses Char3, if it is not 0.
 
658
        Alt+Gr           Uses Char3, if it is not 0.
 
659
 
 
660
  08h   SpecCtlKey. Special action keys, when used with Ctrl pressed:
 
661
 
 
662
        Shift            No effect on these keys.
 
663
        Caps Lock        No effect on these keys.
 
664
        Ctrl             Uses Char2.
 
665
        Alt              See Note 7.
 
666
        Alt+Char         Uses Char3, if it is not 0.
 
667
        Alt+Shift        Uses Char3, if it is not 0.
 
668
        Alt+Gr           Uses Char3, if it is not 0.
 
669
 
 
670
  09h   PrtSc. Print Screen key; sets Char1 normally (see Note 17):
 
671
 
 
672
        Shift            Signal the Print Screen function.
 
673
        Caps Lock        No effect on this key.
 
674
        Ctrl             Sets extended code and signals the Print Echo function.
 
675
        Alt              Marked undefined.
 
676
        Alt+Char         Uses Char3, if it is not 0.
 
677
        Alt+Shift        Uses Char3, if it is not 0.
 
678
        Alt+Gr           Uses Char3, if it is not 0.
 
679
 
 
680
  0Ah   SysReq. System Request key; treated like a shift key. See Note 6.
 
681
 
 
682
  0Bh   AccentKey. Keys that affect the next key pressed (also known as
 
683
        dead keys). Char1 is an index into the AccentTbl field of the
 
684
        XlateTable, selecting the AccentEntry that corresponds to this key.
 
685
        Char2 and Char3 do the same for the shifted Accent character. See
 
686
        Note 15.
 
687
 
 
688
        Shift            Uses Char2 to index to applicable AccentEntry.
 
689
        Caps Lock        No effect on this key.
 
690
        Ctrl             Uses CtlAccent character from AccentEntry. See Note 8.
 
691
        Alt              Uses AltAccent character from AccentEntry. See Note 8.
 
692
        Alt+Char         Uses Char3 to index to applicable AccentEntry.
 
693
        Alt+Shift        Uses Char3 to index to applicable AccentEntry.
 
694
        Alt+Gr           Uses Char3 to index to applicable AccentEntry.
 
695
 
 
696
  Note: Key types 0Ch - 13h set Char1 and Char2 to mask values as defined
 
697
        in Note 6.
 
698
 
 
699
  0Ch   ShiftKeys. Shift or Ctrl key, sets and clears flags. Char1 holds the
 
700
        bits in the lower byte of the shift status word to set when the
 
701
        key is down and clear when the key is released. Char2 does the
 
702
        same thing for the upper byte of the shift status word unless the
 
703
        secondary key prefix (hex E0) is seen immediately prior to this key,
 
704
        in which case Char3 is used in place of Char2.
 
705
 
 
706
  0Dh   ToggleKey. General toggle key (like Caps Lock). Char1 holds the
 
707
        bits in the lower byte of the shift status word to toggle on the
 
708
        first make of the key after it is pressed. Char2 holds the bits in
 
709
        the upper byte of the shift status word to set when the key is
 
710
        down and clear when the key is released unless the secondary key
 
711
        prefix (hex E0) is seen immediately prior to this key, in which case
 
712
        Char3 is used in place of Char2.
 
713
 
 
714
  0Eh   AltKey. Treated just like ShiftKeys above, but has its own key
 
715
        type, because when seen, the accumulator used for Alt+PadKey
 
716
        entry is zeroed to prepare such entry (see Note 5). Sometimes this
 
717
        key is treated as the AltC/S/G key (that is, either Alt+Char,
 
718
        Alt+Shift, or Alt+Gr) if one of the AltGraf bits is on in XTableFlags1.
 
719
 
 
720
  0Fh   Num Lock. Normally behaves like ToggleKey, but the physical
 
721
        keyboard device driver sets a pause screen indication when this
 
722
        key is used with the Ctrl key pressed. The pause is cleared on the
 
723
        following keystroke if that stroke is a character-generating key.
 
724
 
 
725
  10h   Caps Lock. This key is treated as a type 0Dh toggle key. It has a
 
726
        separate entry here so that it can be processed like a Shift Lock
 
727
        key when that flag is set in the XTableFlags1 word in the header.
 
728
        When treated as a Shift Lock, the Caps Lock flag in the shift
 
729
        status word is set on on any make of this key, and only cleared
 
730
        when the left or right shift key is pressed. Char2 and Char3 are
 
731
        processed the same as ToggleKey.
 
732
 
 
733
  11h   Scroll Lock. Normally behaves like ToggleKey but has a separate
 
734
        entry here. When used with Ctrl, it can be recognized as
 
735
        Ctrl+Break.
 
736
 
 
737
  12h   XShiftKey. Extended Shift Key (for Country support). See Note 9.
 
738
 
 
739
  13h   XToggleKey. Extended Toggle Key (for Country support). See Note 9.
 
740
 
 
741
  14h   SpecKeyCS. Special key 1 for country keyboard processing. See Note 15.
 
742
 
 
743
        Shift            Uses Char2.
 
744
        Caps Lock        Uses Char4.
 
745
        Ctrl             See Note 4.
 
746
        Alt              See Note 7.
 
747
        Alt+Char         Uses Char3.
 
748
        Alt+Shift        Uses Char3.
 
749
        Alt+Gr           Uses Char3.
 
750
        Caps+Shift       Uses Char5.
 
751
 
 
752
  15h   SpecKeyAS.  Special key 2 for country keyboard processing. See Note 15.
 
753
 
 
754
        Shift            Uses Char2.
 
755
        Caps Lock        No effect on this key.
 
756
        Ctrl             See Note 4.
 
757
        Alt              Uses Char 4. See Note 14.
 
758
        Alt+Char         Uses Char 3. See Note 14.
 
759
        Alt+Shift        Uses Char 3. See Note 14.
 
760
        Alt+Gr           Uses Char 3. See Note 14.
 
761
 
 
762
  1Ah   Extended Extended key. This corresponds to the BIOS level support
 
763
        provided for INT 16h, Functions 20h, 21h, and 22h.
 
764
 
 
765
        Shift            Uses Char2.
 
766
        Caps Lock        No effect on this key.
 
767
        Ctrl             Uses Char4.
 
768
        Alt              Uses Char5.
 
769
        Alt+Char         Uses Char 3, if not 0.
 
770
        Alt+Shift        Uses Char 3, if not 0.
 
771
        Alt+Gr           Uses Char 3, if not 0.
 
772
  16h-
 
773
  1FFh  Reserved, except for 1Ah, the Extended Extended key (see above).
 
774
 
 
775
* Note 3
 
776
 
 
777
  Undefined Character Code.  Any key combination that does not fall into any
 
778
  of the defined categories.  For example, the Ctrl key pressed along with a
 
779
  key that has no defined control mapping is mapped to the value 0, and the
 
780
  key type is set in the KeyPacket record indicating undefined translation.
 
781
  The KeyPacket record passed to the monitors, if installed, contain the
 
782
  original scan code in the ScanCode field and the 0 in the Character field for
 
783
  this key.  Notice that no character data records with an undefined character
 
784
  code are placed in the keyboard input buffer.
 
785
 
 
786
* Note 4
 
787
 
 
788
  Ctrl Key. The six possible situations that can occur when a key is pressed
 
789
  with only the Ctrl+shift key are shown below:
 
790
 
 
791
    -  The key pressed is an AlphaKey character. In this case, the Ctrl plus
 
792
       Char1 combination defines one of the standard defined control codes
 
793
       (all numbers are decimal):
 
794
 
 
795
           Ctrl-   Mapping   Code Name        Ctrl-   Mapping   Code Name
 
796
           -----   -------   ---------        -----   -------   ---------
 
797
             a        1         SOH             n       14         SO
 
798
             b        2         STX             o       15         SI
 
799
             c        3         ETX             p       16         DLE
 
800
             d        4         EOT             q       17         DC1
 
801
             e        5         ENQ             r       18         DC2
 
802
             f        6         ACK             s       19         DC3
 
803
             g        7         BEL             t       20         DC4
 
804
             h        8         BS              u       21         NAK
 
805
             i        9         HT              v       22         SYN
 
806
             j       10         LF              w       23         ETB
 
807
             k       11         VT              x       24         CAN
 
808
             l       12         FF              y       25         EM
 
809
             m       13         CR              z       26         SUB
 
810
 
 
811
       Notice that any key defined as AlphaKey uses the Char1 code value
 
812
       minus 96 (ASCII code for a) plus 1 to set the mapping shown above.
 
813
       Any scan code defined as AlphaKey must assign to Char1 one of the
 
814
       allowed lower case letters.
 
815
 
 
816
    -  The key pressed is a nonalpha character, such as [, but is not an action
 
817
       key, such as Enter, Backspace, or an arrow key. This is a
 
818
       SpecKey[C][A] in the list of key types in the previous example. In this
 
819
       case, with one exception, the mapping is based on the scan code of the
 
820
       key. Though the key can be relabeled, the Ctrl+Char combination is
 
821
       always mapped based on the scan code of the key using the following
 
822
       table (all numbers are decimal):
 
823
}(*
 
824
            Scan     US Kbd     Mapped     Name of
 
825
            Code     Legend     Value      New Code
 
826
            ----     ------     ------     --------
 
827
              3       2 @          0         Null
 
828
              7       6 ^         30         RS
 
829
             12       - _         31         US   (see Note below)
 
830
             26       [ {         27         Esc
 
831
             27       ] }         29         GS
 
832
             43       \ |         28         FS
 
833
*){
 
834
       Note:  The mapping for the hyphen character (-) is the one exception.
 
835
              The scan code for it is ignored; only the ASCII code for hyphen
 
836
              (decimal 45) is looked for in Char1 when mapping the Ctrl+-
 
837
              combination. This is because there can be more than one
 
838
              occurrence of the hyphen (-) key on the keyboard.  The Ctrl+-
 
839
              (PadKey minus) combination produces character/scan code values
 
840
              of 00/8Eh, respectively.
 
841
 
 
842
    -  The key pressed is an action key such as Enter, Backspace, or an arrow
 
843
       key. These keys generate special values when used in conjunction with
 
844
       the Ctrl key. Those actions are defined in other notes where they
 
845
       apply. Two particular keys in this category are:
 
846
 
 
847
           Ctrl+Enter     = LF(010)
 
848
           Ctrl+Backspace = Del(127)
 
849
 
 
850
    -  The key pressed is a function key, F1 - F12. See the FuncKey
 
851
       description in Note 2.
 
852
 
 
853
    -  The key pressed is an accent key. See Note 8.
 
854
 
 
855
    -  The key is not defined in conjunction with Ctrl. In this case, the key
 
856
       is treated as undefined, as described in Note 3.
 
857
 
 
858
* Note 5
 
859
 
 
860
  PadKey. The pad keys have several uses that depend on various shift
 
861
  states. Some of them are based on their position on the keyboard. Because
 
862
  keyboard layouts change, the hard-coded assumed positions of the keypad
 
863
  keys, with the offset value that must be coded into Char1, are defined
 
864
  below. Any remapping must use the Char1 values shown below for the keys
 
865
  that correspond to the pad keys given by the Legend or Char2 values:
 
866
 
 
867
       US Kbd     Scan     Char1        Char2
 
868
       Legend     Code     Required     US Kbd     With Ctrl
 
869
       -------    ----     ---------    -------    -----------
 
870
       Home  7     71      Decimal 0    ASCII 7    Decimal 119
 
871
       Up    8     72          "   1      "   8      "     141
 
872
       PgUp  9     73          "   2      "   9      "     132
 
873
             -     74          "   3      "   -      "     142
 
874
       Left  4     75          "   4      "   4      "     115
 
875
             5     76          "   5      "   5      "     143
 
876
       Right 6     77          "   6      "   6      "     116
 
877
             +     78          "   7      "   +      "     144
 
878
       End   1     79          "   8      "   1      "     117
 
879
       Down  2     80          "   9      "   2      "     145
 
880
       PgDn  3     81          "  10      "   3      "     118
 
881
       Ins   0     82          "  11      "   0      "     146
 
882
       Del   .     83          "  12      "   .      "     147
 
883
 
 
884
  Notice that when Num Lock is off, or if Shift is active and Num Lock on, the
 
885
  code returned is the extended code. The code returned corresponds to the
 
886
  Legends above (Home, PgUp, and so forth). When Num Lock is on, or if
 
887
  Shift is active and Num Lock is off, the code returned is Char2. Notice that
 
888
  the + and - keys also return Char2 when the shift key is down.
 
889
 
 
890
  When the Alt key is used with the PadKeys, the absolute value of the
 
891
  pressed key (looked up using the required Char1 value) is added to the
 
892
  accumulated value of any of the previous numeric keys pressed, without
 
893
  releasing the Alt key. Before adding the new number to the accumulated
 
894
  value, that accumulation is multiplied by ten, with overflow beyond 255
 
895
  ignored. When Alt is released, the accumulation becomes a Character code
 
896
  and is passed along with a scan code of zero. Notice that if any key other
 
897
  than the 10 numeric keys is pressed, the accumulated value is reset to zero.
 
898
  When the keypad *, -, or + keys are pressed while the Alt key is down, the
 
899
  extended characters 55, 74, and 78 (decimal) are returned, respectively.
 
900
 
 
901
  When AltGraphics is used with the PadKeys, the Char3 value is returned if it
 
902
  is nonzero, and if an AltGraf bit is set in XTableFlags1; otherwise, it is
 
903
  treated the same as the Alt key.
 
904
 
 
905
  On the Enhanced keyboard, the secondary keypad keys return, as an
 
906
  extended character, the scan code of the key plus 80 (decimal) when
 
907
  pressed in conjunction with the Alt key.  The secondary / key returns an
 
908
  extended character of 164, when pressed in conjunction with the Alt key.
 
909
 
 
910
* Note 6
 
911
 
 
912
  State Key. Each state key entry has Char1, Char2, and Char3 defined as
 
913
  follows:
 
914
 
 
915
    -  Char1. A mask to set the appropriate bit in the low byte of the
 
916
       keyboard Shift Flags when the state key is pressed. When the state
 
917
       key is a toggle key, the set bit is toggled each additional time the key
 
918
       is pressed. When the state key is not a toggle key, the set bit is
 
919
       cleared when the key is released.
 
920
 
 
921
    -  Char2. A mask to set the appropriate bit in the high byte of the
 
922
       Keyboard Shift Flags when the key is pressed.
 
923
 
 
924
    -  Char3. Used in place of Char2 when the secondary key prefix is seen
 
925
       immediately prior to this key.
 
926
 
 
927
  The masks are shown below (numbers are in hex):
 
928
 
 
929
       Key            Char1    Char2    Char3
 
930
       -----------    -----    -----    -----
 
931
       Right Shift      01       00       00
 
932
       Left Shift       02       00       00
 
933
       Ctrl Shift       04       01       04
 
934
       Alt Shift        08       02       08
 
935
       Scroll Lock      10       10       10
 
936
       Num Lock         20       20       20
 
937
       Caps Lock        40       40       40
 
938
       SysReq           00       80       80
 
939
 
 
940
  Notice that the INS key is not treated as a state key, but as a pad key.
 
941
  Also, SysReq is included here because it is treated as a shift key.
 
942
 
 
943
* Note 7
 
944
 
 
945
  Alt Character. Most of the keys defined in a category that allows the Alt
 
946
  key (AlphaKey, SpecKeyA, SpecKeyCA) return a value called an extended
 
947
  character. This value is a character code of 00H or E0H, with a second byte
 
948
  (using the ScanCode field of the CharData record) defining the extended
 
949
  code. In most cases, this value is the scan code of the key. Since the
 
950
  legend on these keys can be remapped on a foreign language keyboard, the
 
951
  Alt-based extended code is hard to define in a general sense. The following
 
952
  rules are used:
 
953
 
 
954
    -  AlphaKey. The extended code is derived from Char1 (the lower-case
 
955
       character) as it was originally mapped on the PC keyboard. The
 
956
       original scan code value is the extended code that a character returns.
 
957
       These keys can be moved and will still return their original Alt
 
958
       extended codes.
 
959
 
 
960
    -  SpecKeyA and SpecKeyCA. This category is used for all keys that are
 
961
       not an alphabetic character or an action code (like Enter or Backspace,
 
962
       the only exception being the Tab key, which is treated as a character).
 
963
       On foreign keyboards, these keys can be moved around and can have
 
964
       new values assigned to them, such as special punctuation symbols.
 
965
       Therefore, the Alt mappings must be based on the real scan code as
 
966
       any keys defined by the SpecKey_ classification will have only an Alt
 
967
       mapping, if it is in one of the positions defined below. In that case,
 
968
       the Alt extended code is as shown:
 
969
}(*
 
970
           Scan    US Kbd    Alt          Scan    US Kbd    Alt
 
971
           Code    Legend    Value        Code    Legend    Value
 
972
           ----    ------    -----        ----    ------    -----
 
973
             2      1 !       120          15      Tab       165
 
974
             3      2 @       121          26      [ {        26
 
975
             4      3 #       122          27      ] }        27
 
976
             5      4 $       123          28      Enter      28
 
977
             6      5 %       124          39      ; :        39
 
978
             7      6 ^       125          40      ' "        40
 
979
             8      7 &       126          41      ' ~        41
 
980
             9      8 *       127          43      \ |        43  (equals W.T.C. key number 42)
 
981
            10      9 (       128          51      , <        51
 
982
            11      0 )       129          52      . >        52
 
983
            12      - _       130          53      / ?        53
 
984
            13      = +       131
 
985
*){
 
986
       The secondary / key returns an extended character of 164 when
 
987
       pressed while Alt is down.
 
988
 
 
989
    -  FuncKey. Defined in Note 2.
 
990
 
 
991
    -  SpecCtlKey. The Alt+ values of the Escape, Backspace, and Enter keys
 
992
       are extended characters equaling 1, 14, and 28 (decimal), respectively.
 
993
 
 
994
  When AltGraphics is used, the Char3 value is returned if it is nonzero and if
 
995
  an AltGraf bit is set in XTableFlags1. Otherwise, it is treated the same as
 
996
  the Alt key.
 
997
 
 
998
* Note 8
 
999
 
 
1000
  Accent Key. When an accent key is pressed with Ctrl or Alt, it is treated as
 
1001
  a regular key. The character it translates to is the one in the CtlAccent or
 
1002
  AltAccent field of the AccentEntry pointed to by the Char5 value of the
 
1003
  KeyDef. If the key being defined has no defined value with Ctrl or Alt, it
 
1004
  should have zeros in the field of the undefined combination.
 
1005
 
 
1006
  When an accent key is pressed by itself (or with Right Shift, Left Shift, or
 
1007
  AltGraphics), it is not translated immediately. The Char1 (or Char2, when
 
1008
  Left or Right Shift or AltGraphics is used) index in the KeyDef record is
 
1009
  used with the next key received to check if the next key has an accent
 
1010
  mapping. If that next key has no mapping for this accent (that is, if it has
 
1011
  no bit set in its AccentFlags), or if that next key is not found in this
 
1012
  accent's AccentEntry, then the character value in the NonAccent field of the
 
1013
  AccentEntry is used as the character to display. It is followed by the
 
1014
  translation of that next key after the not-an-accent beep is sounded.
 
1015
 
 
1016
  Notice that if a key doesn't change when a Left or Right Shift key is
 
1017
  pressed, it should use the same value for Char1 and Char2 so the accent
 
1018
  applies in both the shifted and nonshifted cases. If the accent value is
 
1019
  undefined when used with a shift key or AltGraphics, the value in Char2 or
 
1020
  Char3 should be 0.
 
1021
 
 
1022
  Any accent key that doesn't have an Alt or Ctrl mapping should put zeros in
 
1023
  the AltAccent and CtlAccent fields of its AccentEntry. If the value in the
 
1024
  table is between 1 and 7, then the key is considered an accent key and
 
1025
  further accent key processing is indicated. See Note 1 for more information.
 
1026
 
 
1027
* Note 9
 
1028
 
 
1029
  Extended State Key. For special Country support, the keyboard device
 
1030
  driver maintains another byte of shift status. Key types 12h and 13h are
 
1031
  provided for manipulation of that byte. The other fields of the KeyDef are:
 
1032
 
 
1033
    -  Char1. A mask in which bits that are on define the field being used for
 
1034
       the Char2 value. Only bits in the NLS shift status byte that correspond
 
1035
       to the bits in this byte are altered by the Char2 value.
 
1036
 
 
1037
    -  Char2. For KeyType 12h (Extended Shift), the value to OR into the
 
1038
       byte when the make code is seen. Also, the inverted value is ANDed
 
1039
       when the break code is seen. For KeyType 13h (Extended Toggle), the
 
1040
       value XORed into the byte on each make code seen (break code
 
1041
       ignored).
 
1042
 
 
1043
    -  Char3. Use in place of the Char2 when the secondary key prefix (hex
 
1044
       E0) is seen immediately prior to this key.
 
1045
 
 
1046
  For example, Char1 or Char2 can define single shift status bits to
 
1047
  set/clear/toggle. Char2 can be a set of coded bits, delineated by Char1, that
 
1048
  are set to a numeric value when the key is pressed and cleared to zero
 
1049
  when released (or on the next press, if toggled). The whole byte can be
 
1050
  set to Char2 when Char1 has all bits on.
 
1051
 
 
1052
* Note 10
 
1053
 
 
1054
  Space Key. The key treated as the space character should have a flag set
 
1055
  in its AccentFlags field for each possible accent (that is, for each defined
 
1056
  AccentEntry in the AccentTable). And each AccentEntry should have the
 
1057
  Space character defined as one of its accented characters, with the
 
1058
  translation having the same value as the accent character itself. The reason
 
1059
  for this is that, by definition, an Accent Key followed by the space
 
1060
  character maps to the accent character alone. If the table is not set up as
 
1061
  just described, a not-an-accent beep is sounded whenever the accent key
 
1062
  followed by a space is pressed.
 
1063
 
 
1064
  Notice that the space key is defined as a SpecKeyA (type 4) because its
 
1065
  use, in conjunction with the Alt key, is allowed. In this case, and when
 
1066
  used with the Ctrl key, it returns the ASCII space character. This works
 
1067
  correctly, except in the case of the diaresis accent (double-dot) in code
 
1068
  page 437. The space is treated as an invalid character and the beep result
 
1069
  occurs, with the diaresis represented by double quotation marks. The
 
1070
  characters displayed depend upon the language in effect when the invalid
 
1071
  diaresis is encountered. For some languages, the character substituted is
 
1072
  the double-quotation marks; for others, the character used is the F9h
 
1073
  character.
 
1074
 
 
1075
* Note 11
 
1076
 
 
1077
  KbdType identifies the hardware-specific keyboard used by this table. The
 
1078
  values and allowable types are the same as those specified in IOCTL call
 
1079
  KBD_GETKEYBDTYPE (1 means extended keyboard, which is used for all common
 
1080
  keyboard types).
 
1081
 
 
1082
* Note 12
 
1083
 
 
1084
  The DefaultTable flag in XtableFlags1 is used by the KEYB utility in loading
 
1085
  code pages when changing from one language to another. It identifies the
 
1086
  default code page to KEYB, should KEYB not find one or both CODEPAGE=
 
1087
  defined code pages.
 
1088
 
 
1089
* Note 13
 
1090
 
 
1091
  The Language IDs and Subcountry IDs used are as follows:
 
1092
 
 
1093
  ������������������������������������������������������Ŀ
 
1094
  �Keyboard Layout �Keyboard Layout �Country             �
 
1095
  �Country Code    �SubCountry Code �                    �
 
1096
  ������������������������������������������������������Ĵ
 
1097
  �       AR       �       785      �Arabic-speaking     �
 
1098
  ������������������������������������������������������Ĵ
 
1099
  �       BE       �       120      �Belgium             �
 
1100
  ������������������������������������������������������Ĵ
 
1101
  �       CF       �       058      �Canadian-French     �
 
1102
  ������������������������������������������������������Ĵ
 
1103
  �       CS       �       243      �Czech Republic      �
 
1104
  ������������������������������������������������������Ĵ
 
1105
  �       CS       �       245      �Czech Republic      �
 
1106
  ������������������������������������������������������Ĵ
 
1107
  �       DK       �       159      �Denmark             �
 
1108
  ������������������������������������������������������Ĵ
 
1109
  �       SU       �       153      �Finland             �
 
1110
  ������������������������������������������������������Ĵ
 
1111
  �       FR       �       120      �France              �
 
1112
  ������������������������������������������������������Ĵ
 
1113
  �       FR       �       189      �France              �
 
1114
  ������������������������������������������������������Ĵ
 
1115
  �       GR       �       129      �Germany             �
 
1116
  ������������������������������������������������������Ĵ
 
1117
  �       HE       �       972      �Hebrew-speaking     �
 
1118
  ������������������������������������������������������Ĵ
 
1119
  �       HU       �       208      �Hungary             �
 
1120
  ������������������������������������������������������Ĵ
 
1121
  �       IS       �       197      �Iceland             �
 
1122
  ������������������������������������������������������Ĵ
 
1123
  �       IT       �       141      �Italy               �
 
1124
  ������������������������������������������������������Ĵ
 
1125
  �       IT       �       142      �Italy               �
 
1126
  ������������������������������������������������������Ĵ
 
1127
  �       LA       �       171      �Latin-American      �
 
1128
  �                �                �Spanish             �
 
1129
  ������������������������������������������������������Ĵ
 
1130
  �       NL       �       143      �Netherlands         �
 
1131
  ������������������������������������������������������Ĵ
 
1132
  �       NO       �       155      �Norway              �
 
1133
  ������������������������������������������������������Ĵ
 
1134
  �       PL       �       214      �Poland              �
 
1135
  ������������������������������������������������������Ĵ
 
1136
  �       PO       �       163      �Portugal            �
 
1137
  ������������������������������������������������������Ĵ
 
1138
  �       SP       �       172      �Spain               �
 
1139
  ������������������������������������������������������Ĵ
 
1140
  �       SV       �       153      �Sweden              �
 
1141
  ������������������������������������������������������Ĵ
 
1142
  �       SF       �       150F     �Swiss-French        �
 
1143
  ������������������������������������������������������Ĵ
 
1144
  �       SG       �       150G     �Swiss-German        �
 
1145
  ������������������������������������������������������Ĵ
 
1146
  �       TR       �       179      �Turkey              �
 
1147
  ������������������������������������������������������Ĵ
 
1148
  �       UK       �       166      �United Kingdom      �
 
1149
  ������������������������������������������������������Ĵ
 
1150
  �       UK       �       168      �United Kingdom      �
 
1151
  ������������������������������������������������������Ĵ
 
1152
  �       US       �       103      �United States       �
 
1153
  ������������������������������������������������������Ĵ
 
1154
  �       YU       �       234      �Former Yugoslavia   �
 
1155
  ��������������������������������������������������������
 
1156
 
 
1157
* Note 14
 
1158
 
 
1159
  Keytype 15. When the Alt or Alt+Shift keys are pressed, both XlatedChar
 
1160
  and XlatedScan in the CharData record will have the same value.
 
1161
 
 
1162
* Note 15
 
1163
 
 
1164
  If the Charx value is in the range of 1-7, then Charx identifies an accent
 
1165
  key. Otherwise, Charx is treated as a valid ASCII character. This does not
 
1166
  apply to Ctrl+Charx sequences.
 
1167
 
 
1168
  Note 16
 
1169
 
 
1170
  If Alt+Gr, Alt+Shift, or Alt+Ctrl are pressed, and Char3 is 0, the Alt key is
 
1171
  used to translate to a valid result.
 
1172
 
 
1173
  Note 17
 
1174
 
 
1175
  The * key on the keypad of the Enhanced keyboard, although producing the
 
1176
  same scan code/character as that of the IBM Personal Computer AT*
 
1177
  keyboard, is treated differently because a dedicated Print Screen key exists
 
1178
  on the Enhanced keyboard. The following scan codes/characters are
 
1179
  returned by the physical keyboard device driver for the Enhanced keyboard
 
1180
  * key on the keypad:
 
1181
 
 
1182
  Unshifted    37H/2AH
 
1183
  Shifted      37H/2AH
 
1184
  Ctrl         96H/00
 
1185
  Alt          37H/00
 
1186
 
 
1187
* Note 18
 
1188
 
 
1189
  Size. The code page described here has the following dimensions:
 
1190
 
 
1191
      Xlate Header                =    40
 
1192
      127 KeyDefs @ 7 bytes       =   889
 
1193
      7 AccentEntries @ 46 bytes  =   322
 
1194
                                     ----
 
1195
                                     1251 bytes
 
1196
 
 
1197
  If more than 6 AccentEntries are needed, then the following format is used:
 
1198
  In the first 6 AccentEntries, the length is set at 20, with unused elements
 
1199
  set to zero. For each AccentEntry of 7 and greater, up to 120 element pairs
 
1200
  may exist, and the length is dynamic.
 
1201
 
 
1202
  For each AccentEntry of 7 and greater, the first byte in the record will
 
1203
  contain the LENGTH of the AccentEntry record. The LENGTH value is defined
 
1204
  as the total length in bytes of the AccentEntry record including the LENGTH
 
1205
  byte.
 
1206
 
 
1207
  The record is defined as follows:
 
1208
 
 
1209
    AccEnt <l,a,b,c,d,e,f,c1,s1,c2,s2..c120,s120>
 
1210
    where....
 
1211
    l is the total length in bytes of the AccEnt including itself.
 
1212
    a &b are the scan code &char to use when the key following this accent
 
1213
    is not affected by the accent so the accent itself must be used.
 
1214
    c &d are the scan code &char to use when Ctl+[accent] is pressed.
 
1215
    e &f do the same for Alt+[accent].
 
1216
    c1,s1 - c120,s120 are the char/scan code mapping for accented translation.
 
1217
 
 
1218
  Adding more than 7 accents will make the standard 1251-byte table an
 
1219
  extended variable size.
 
1220
}
 
1221
 
 
1222
 
 
1223
 
 
1224
{Register a keyboard subsystem within a session.}
 
1225
{ModuleName - dynamic link module name, maximum length is 8 bytes, ProcName is
 
1226
a dynamic link entry point name of a routine that receives control when any of
 
1227
the registered functions are called. Maximum length is 32 bytes, FnMask - see
 
1228
KR_* constants}
 
1229
{Possible return codes:
 
1230
    0         No_Error
 
1231
    408       Error_Kbd_Invalid_ASCIIZ
 
1232
    409       Error_Kbd_Invalid_Mask
 
1233
    410       Error_Kbd_Register
 
1234
    464       Error_Kbd_Detached
 
1235
    504       Error_Kbd_Extended_SG}
 
1236
{Remarks:
 
1237
* There can be only one KbdRegister call outstanding for each session without
 
1238
  an intervening KbdDeRegister. KbdDeRegister must be issued by the same
 
1239
  process that issued the KbdRegister.}
 
1240
function KbdRegister(ModuleName,ProcName:PChar;FnMask:cardinal):word; cdecl;
 
1241
function KbdRegister(ModuleName,ProcName:string;FnMask:cardinal):word;
 
1242
 
 
1243
{Deregister a keyboard subsystem previously registered within a session - only
 
1244
the process that issued the KbdRegister may issue KbdDeRegister.}
 
1245
{Possible return codes:
 
1246
    0         No_Error
 
1247
    411       Error_Kbd_Deregister
 
1248
    464       Error_Kbd_Detached
 
1249
    504       Error_Kbd_Extended_SG}
 
1250
function KbdDeRegister:word; cdecl;
 
1251
 
 
1252
{Return a character data record from the keyboard.}
 
1253
{Key - see TKbdKeyInfo record type, WaitFlag - see IO_Wait and IO_NoWait
 
1254
constants, KbdHandle is the default keyboard (0) or a logical keyboard.}
 
1255
{Possible return codes are:
 
1256
    0         No_Error
 
1257
    375       Error_Kbd_Invalid_IOWait
 
1258
    439       Error_Kbd_Invalid_Handle
 
1259
    445       Error_Kbd_Focus_Required
 
1260
    447       Error_Kbd_Keyboard_Busy
 
1261
    464       Error_Kbd_Detached
 
1262
    504       Error_Kbd_Extended_SG}
 
1263
{Remarks:
 
1264
* On an enhanced keyboard, the secondary enter key returns the normal
 
1265
  character 0Dh and a scan code of E0h.
 
1266
* Double-byte character codes (DBCS) require two function calls to obtain the
 
1267
  entire code.
 
1268
* If shift report is set with KbdSetStatus, the CharData record returned
 
1269
  reflects changed shift information only.
 
1270
* Extended ASCII codes are identified with the status byte, bit 1 on and the
 
1271
  ASCII character code being either 00h or E0h. Both conditions must be
 
1272
  satisfied for the character to be an extended keystroke.  For extended
 
1273
  ASCII codes, the scan code byte returned is the second code (extended
 
1274
  code). Usually the extended ASCII code is the scan code of the primary key
 
1275
  that was pressed.
 
1276
* A thread in the foreground session that repeatedly polls the keyboard with
 
1277
  KbdCharIn (with no wait), can prevent all regular priority class threads
 
1278
  from executing.  If polling must be used and a minimal amount of other
 
1279
  processing is being performed, the thread should periodically yield to the
 
1280
  CPU by issuing a DosSleep call for an interval of at least 5 milliseconds.}
 
1281
function KbdCharIn(var Key:TKbdKeyInfo;WaitFlag,KbdHandle:word):word; cdecl;
 
1282
 
 
1283
{Return any available character data record from the keyboard
 
1284
without removing it from the buffer.}
 
1285
{Key - see TKbdKeyInfo record type, KbdHandle is the default keyboard (0)
 
1286
or a logical keyboard.}
 
1287
{Possible return codes are:
 
1288
    0         No_Error
 
1289
    439       Error_Kbd_Invalid_Handle
 
1290
    445       Error_Kbd_Focus_Required
 
1291
    447       Error_Kbd_Keyboard_Busy
 
1292
    464       Error_Kbd_Detached
 
1293
    504       Error_Kbd_Extended_SG}
 
1294
{Remarks:
 
1295
* On an enhanced keyboard, the secondary enter key returns the normal
 
1296
  character 0Dh and a scan code of E0h.
 
1297
* Double-byte character codes (DBCS) require two function calls to obtain the
 
1298
  entire code.
 
1299
* If shift report is set with KbdSetStatus the CharData record returned,
 
1300
  reflects changed shift information only.
 
1301
* Extended ASCII codes are identified with the status byte, bit 1 on and the
 
1302
  ASCII character code being either 00h or E0h. Both conditions must be
 
1303
  satisfied for the character to be an extended keystroke. For extended
 
1304
  ASCII codes, the scan code byte returned is the second code (extended
 
1305
  code). Usually the extended ASCII code is the scan code of the primary key
 
1306
  that was pressed.
 
1307
* A thread in the foreground session that repeatedly polls the keyboard with
 
1308
  KbdCharIn (with no wait), can prevent all regular priority class threads
 
1309
  from executing. If polling must be used and a minimal amount of other
 
1310
  processing is being performed, the thread should periodically yield the CPU
 
1311
  by issuing a DosSleep call for an interval of at least 5 milliseconds.}
 
1312
function KbdPeek(var Key:TKbdKeyInfo;KbdHandle:word):word; cdecl;
 
1313
 
 
1314
{Read a character string (character codes only) from the keyboard.}
 
1315
{CharBuf is a buffer for returned characters, LenInOut - see TStringInBuf
 
1316
record type, WaitFlag - see IO_Wait and IO_NoWait constants, KbdHandle is the
 
1317
default keyboard (0) or a logical keyboard.}
 
1318
{Possible return codes are:
 
1319
    0         No_Error
 
1320
    375       Error_Kbd_Invalid_IOWait
 
1321
    439       Error_Kbd_Invalid_Handle
 
1322
    445       Error_Kbd_Focus_Required
 
1323
    464       Error_Kbd_Detached
 
1324
    504       Error_Kbd_Extended_SG}
 
1325
{Remarks:
 
1326
* The character strings may be optionally echoed on the display if echo mode
 
1327
  is set. When echo is on each character is echoed as it is read from the
 
1328
  keyboard. Echo mode and binary mode are mutually exclusive. Reference
 
1329
  KbdSetStatus and KbdGetStatus for more information.
 
1330
* The default input mode is ASCII. In ASCII mode, 2-byte character codes only
 
1331
  return in complete form. An extended ASCII code is returned in a 2-byte
 
1332
  string. The first byte is 0Dh or E0h and the next byte is an extended code.
 
1333
* In input mode (binary, ASCII), the following returns can be set and
 
1334
  retrieved with KbdSetStatus and KbdGetStatus:
 
1335
    Turnaround Character
 
1336
    Echo Mode
 
1337
    Interim Character Flag
 
1338
    Shift State
 
1339
* The received input length is also used by the KbdStringIn line edit
 
1340
  functions for re-displaying and entering a caller specified string. On the
 
1341
  next KbdStringIn call the received input length indicates the length of the
 
1342
  input buffer that may be recalled by the user using the line editing keys.
 
1343
  A value of 0 inhibits the line editing function for the current KbdStringIn
 
1344
  request.
 
1345
* KbdStringIn completes when the handle has access to the physical keyboard
 
1346
  (focus), or is equal to zero and no other handle has the focus.}
 
1347
function KbdStringIn(var CharBuf;var LenInOut:TStringInBuf;WaitFlag:word;
 
1348
                                                   KbdHandle:word):word; cdecl;
 
1349
function KbdStringIn(CharBuf:PChar;LenInOutP:PStringInBuf;WaitFlag:word;
 
1350
                                                   KbdHandle:word):word; cdecl;
 
1351
 
 
1352
{Clear the keystroke buffer.}
 
1353
{KbdHandle is the default keyboard (0) or a logical keyboard.}
 
1354
{Possible return codes are:
 
1355
    0         No_Error
 
1356
    439       Error_Kbd_Invalid_Handle
 
1357
    445       Error_Kbd_Focus_Required
 
1358
    447       Error_Kbd_Keyboard_Busy
 
1359
    464       Error_Kbd_Detached
 
1360
    504       Error_Kbd_Extended_SG}
 
1361
{Remarks:
 
1362
* KbdFlushBuffer completes when the handle has access to the physical
 
1363
  keyboard (focus), or is equal to zero and no other handle has the focus.}
 
1364
function KbdFlushBuffer(KbdHandle:word):word; cdecl;
 
1365
 
 
1366
{Set the characteristics of the keyboard.}
 
1367
{Status - see TKbdInfo record type, KbdHandle is the default keyboard (0) or
 
1368
a logical keyboard.}
 
1369
{Possible return codes are:
 
1370
    0         No_Error
 
1371
    376       Error_Kbd_Invalid_length
 
1372
    377       Error_Kbd_Invalid_Echo_Mask
 
1373
    378       Error_Kbd_Invalid_Input_Mask
 
1374
    439       Error_Kbd_Invalid_Handle
 
1375
    445       Error_Kbd_Focus_Required
 
1376
    447       Error_Kbd_Keyboard_Busy
 
1377
    464       Error_Kbd_Detached
 
1378
    504       Error_Kbd_Extended_SG}
 
1379
{Remarks:
 
1380
* Shift return (bit 8 in sysstate) must be disabled in ASCII mode.
 
1381
* KbdSetStatus is ignored for a Vio-windowed application.}
 
1382
function KbdSetStatus(var Status:TKbdInfo;KbdHandle:word):word; cdecl;
 
1383
 
 
1384
{Get the current state of the keyboard.}
 
1385
{Status - see TKbdInfo record type, KbdHandle is the default keyboard (0) or
 
1386
a logical keyboard.}
 
1387
{Possible return codes:
 
1388
    0         No_Error
 
1389
    376       Error_Kbd_Invalid_Length
 
1390
    439       Error_Kbd_Invalid_Handle
 
1391
    445       Error_Kbd_Focus_Required
 
1392
    447       Error_Kbd_Keyboard_Busy
 
1393
    464       Error_Kbd_Detached
 
1394
    504       Error_Kbd_Extended_SG}
 
1395
{Remarks:
 
1396
* The initial state of the keyboard is established by the system at
 
1397
  application load time. Some default states may be modified by the
 
1398
  application through KbdSetStatus. KbdGetStatus returns only those keyboard
 
1399
  parameters initially set by KbdSetStatus. The returned parameters are:
 
1400
  Input Mode, Interim Character Flags, Shift State, Echo State, TurnAround
 
1401
  Character
 
1402
* KbdGetStatus completes only when the handle has access to the physical
 
1403
  keyboard (focus) or the handle is 0 and no other handle has the focus.}
 
1404
function KbdGetStatus(var Status:TKbdInfo;KbdHandle:word):word; cdecl;
 
1405
 
 
1406
{Set the code page used to translate key strokes received from the keyboard for
 
1407
current process.}
 
1408
{Reserved - reserved, must be set to 0, CodePage - code-page ID in the
 
1409
application's data area, must be equivalent to one of the code-page IDs
 
1410
specified on the CONFIG.SYS CODEPAGE= statement or 0, an error results
 
1411
otherwise, KbdHandle is the default keyboard (0) or a logical keyboard.}
 
1412
{Possible return codes:
 
1413
    0         No_Error
 
1414
    439       Error_Kbd_Invalid_Handle
 
1415
    445       Error_Kbd_Focus_Required
 
1416
    447       Error_Kbd_Keyboard_Busy
 
1417
    448       Error_Kbd_Invalid_CodePage
 
1418
    464       Error_Kbd_Detached
 
1419
    504       Error_Kbd_Extended_SG}
 
1420
{Remarks:
 
1421
* Keyboard code page support is not available without the DEVINFO=KBD
 
1422
  statement in the CONFIG.SYS file.}
 
1423
function KbdSetCp(Reserved,CodePage,KbdHandle:word):word; cdecl;
 
1424
 
 
1425
{Query the code page being used to translate scan codes to ASCII characters.}
 
1426
{Reserved must be set to 0. The keyboard support returns the current code
 
1427
page for a specified keyboard handle in CodePage, it is one of the code page
 
1428
IDs specified in the CONFIG.SYS CODEPAGE= statement or 0000. KbdHandle is
 
1429
the default keyboard (0) or a logical keyboard.}
 
1430
{Possible return codes:
 
1431
    0         No_Error
 
1432
    373       Error_Kbd_Parameter
 
1433
    439       Error_Kbd_Invalid_Handle
 
1434
    445       Error_Kbd_Focus_Required
 
1435
    447       Error_Kbd_Keyboard_Busy
 
1436
    464       Error_Kbd_Detached
 
1437
    504       Error_Kbd_Extended_SG}
 
1438
{Remarks:
 
1439
* CodePage is set to the currently active keyboard code page. A value of 0
 
1440
  indicates the code page translation table in use is the ROM code page
 
1441
  translation table provided by the hardware.}
 
1442
function KbdGetCp(Reserved:cardinal;var CodePage:word;KbdHandle:word):word;
 
1443
                                                                         cdecl;
 
1444
 
 
1445
{Create a new logical keyboard.}
 
1446
{Handle for the new logical keyboard returned in KbdHandle.}
 
1447
{Possible return codes:
 
1448
    0         No_Error
 
1449
    440       Error_Kbd_No_More_Handle
 
1450
    441       Error_Kbd_Cannot_Create_KCB
 
1451
    464       Error_Kbd_Detached
 
1452
    504       Error_Kbd_Extended_SG}
 
1453
{Remarks:
 
1454
* KbdOpen blocks while another thread has the keyboard focus (by way of
 
1455
  KbdGetFocus) until the thread with the focus issues KbdFreeFocus.
 
1456
  Therefore, to prevent KbdOpen from blocking, it is recommended that KbdOpen
 
1457
  be issued only while the current thread has the focus. For example:
 
1458
    KbdGetFocus     wait until focus available on handle 0
 
1459
    KbdOpen         get a logical keyboard handle
 
1460
    KbdFreeFocus    give up the focus on handle 0}
 
1461
function KbdOpen(var KbdHandle:word):word; cdecl;
 
1462
 
 
1463
{Close the existing logical keyboard identified by the keyboard handle}
 
1464
{KbdHandle is the default keyboard (0) or a logical keyboard}
 
1465
{Possible return codes:
 
1466
    0         No_Error
 
1467
    439       Error_Kbd_Invalid_Handle
 
1468
    464       Error_Kbd_Detached
 
1469
    504       Error_Kbd_Extended_SG}
 
1470
{Remarks:
 
1471
* KbdClose blocks while another thread has the keyboard focus (by way of
 
1472
  KbdGetFocus) until the thread with the focus issues KbdFreeFocus.
 
1473
  Therefore, to prevent KbdClose from blocking, it is recommended that
 
1474
  KbdClose be issued only while the current thread has the focus.  For
 
1475
  example:
 
1476
    KbdGetFocus     wait until focus available on handle 0
 
1477
    KbdClose        close a logical keyboard handle
 
1478
    KbdFreeFocus    give up the focus on handle 0}
 
1479
function KbdClose(KbdHandle:word):word; cdecl;
 
1480
 
 
1481
{Bind the logical keyboard to the physical keyboard.}
 
1482
{KbdHandle is the default keyboard (0) or a logical keyboard}
 
1483
{Possible return codes:
 
1484
    0         No_Error
 
1485
    439       Error_Kbd_Invalid_Handle
 
1486
    445       Error_Kbd_Focus_Required
 
1487
    464       Error_Kbd_Detached
 
1488
    504       Error_Kbd_Extended_SG}
 
1489
function KbdGetFocus(WaitFlag,KbdHandle:word):word; cdecl;
 
1490
 
 
1491
{Free the logical-to-physical keyboard bond created by KbdGetFocus.}
 
1492
{KbdHandle is the default keyboard (0) or a logical keyboard}
 
1493
{Possible return codes:
 
1494
    0         No_Error
 
1495
    439       Error_Kbd_Invalid_Handle
 
1496
    445       Error_Kbd_Focus_Required
 
1497
    464       Error_Kbd_Detached
 
1498
    504       Error_Kbd_Extended_SG}
 
1499
{Remarks:
 
1500
* KbdFreeFocus may be replaced by issuing KbdRegister. Unlike other keyboard
 
1501
  subsystem functions, the replaced KbdFreeFocus is called only if there is
 
1502
  an outstanding focus.}
 
1503
function KbdFreeFocus(KbdHandle:word):word; cdecl;
 
1504
 
 
1505
{Synchronize access from a keyboard subsystem to the keyboard device driver.}
 
1506
{WaitFlag - see IO_Wait and IO_NoWait constants (wait / don't wait for access
 
1507
to the device driver.}
 
1508
{Possible return codes:
 
1509
    0         No_Error
 
1510
    121       Error_Sem_TimeOut}
 
1511
{Remarks:
 
1512
* KbdSynch blocks all other threads within a session until return from the
 
1513
  subsystem to the router. To ensure proper synchronization, KbdSynch should
 
1514
  be issued by a keyboard subsystem if it intends to issue a DosDevIOCtl or
 
1515
  access dynamically shared data. KbdSynch does not protect globally shared
 
1516
  data from threads in other sessions.}
 
1517
function KbdSynch (WaitFlag:word):word; cdecl;
 
1518
 
 
1519
{Raise the priority of the foreground keyboard's thread.}
 
1520
{Possible return codes:
 
1521
    0         No_Error
 
1522
    447       Error_Kbd_Keyboard_Busy
 
1523
    504       Error_Kbd_Extended_SG}
 
1524
{Remarks:
 
1525
* KbdSetFgnd marks the current process that owns the keyboard. Threads in
 
1526
  this process receive a priority boost. The previous foreground keyboard
 
1527
  threads lose their priority boost.
 
1528
* This function should only be issued by a Keyboard Subsystem during
 
1529
  KbdCharIn or KbdStringIn processing.}
 
1530
function KbdSetFgnd:word; cdecl;
 
1531
 
 
1532
{Return the attached keyboard's hardware-generated identification value.}
 
1533
{HWID is a pointer to the caller's data area, see TKbdHWID, KbdHandle is the
 
1534
default keyboard (0) or a logical keyboard.}
 
1535
{Possible return codes:
 
1536
    0         No_Error
 
1537
    373       Error_Kbd_Parameter
 
1538
    447       Error_Kbd_Keyboard_Busy
 
1539
    464       Error_Kbd_Detached
 
1540
    504       Error_Kbd_Extended_SG}
 
1541
{Remarks:
 
1542
* In past OS/2 releases, all keyboards could be supported by knowing the
 
1543
  hardware family information available with keyboard IOCTL 77h. However,
 
1544
  with the addition of the 122-key keyboard, recognition was not containable
 
1545
  by hardware family information alone. The 122-key keyboard has a number of
 
1546
  differences from other keyboards. Therefore, applications performing
 
1547
  keystroke specific functions may need to determine specifically which
 
1548
  keyboard is attached.
 
1549
* This function is of particular usefulness for applications providing Custom
 
1550
  Translate Tables and mapping keyboard layouts.}
 
1551
function KbdGetHWID(var HWID:TKbdHWID;KbdHandle:word):word; cdecl;
 
1552
 
 
1553
{Undocumented in official IBM documentation}
 
1554
function KbdSetHWID(var HWID:TKbdHWID;KbdHandle:word):word; cdecl;
 
1555
function KbdSetHWID(HWIDP:PKbdHWID;KbdHandle:word):word; cdecl;
 
1556
 
 
1557
{Translate scan codes with shift states into ASCII codes.}
 
1558
{TransData - see TKbdTransData, KbdHandle is the default keyboard (0) or a
 
1559
logical keyboard.}
 
1560
{Possible return codes:
 
1561
    0         No_Error
 
1562
    439       Error_Kbd_Invalid_Handle
 
1563
    445       Error_Kbd_Focus_Required
 
1564
    447       Error_Kbd_Keyboard_Busy
 
1565
    464       Error_Kbd_Detached
 
1566
    504       Error_Kbd_Extended_SG}
 
1567
{Remarks:
 
1568
* It may take several calls to complete a translation because of accent key
 
1569
  combinations, or other complex operations.
 
1570
* The fsShift and sZero are for use by the keyboard translation routines.
 
1571
  These fields are reserved and must only be accessed by the caller prior
 
1572
  to starting a translation sequence and then they must be set to zero.
 
1573
  The KbdXlate function is intended to be used for translating a particular
 
1574
  scan code for a given shift state. The KbdXlate function is not intended
 
1575
  to be a replacement for the OS/2 system keystroke translation function.}
 
1576
function KbdXlate(var TransData:TKbdTrans;KbdHandle:word):word; cdecl;
 
1577
 
 
1578
{Install, on the specified handle, the translate table which this call points
 
1579
to. This translate table affects only this handle.}
 
1580
{XLateTbl is the translation table used to translate scan code to ASCII code
 
1581
for a specified handle (the format of the translation table is documented in
 
1582
the Set Code Page IOCTL 50h), KbdHandle is the default keyboard (0) or a
 
1583
logical keyboard.}
 
1584
{Possible return codes:
 
1585
    0         No_Error
 
1586
    377       Error_Kbd_Invalid_Echo_Mask
 
1587
    378       Error_Kbd_Invalid_Input_Mask
 
1588
    439       Error_Kbd_Invalid_Handle
 
1589
    445       Error_Kbd_Focus_Required
 
1590
    447       Error_Kbd_Keyboard_Busy
 
1591
    464       Error_Kbd_Detached
 
1592
    504       Error_Kbd_Extended_SG}
 
1593
{Remarks:
 
1594
* The translate table must be maintained in the caller's memory. No copy of
 
1595
  the translate table is made by KbdSetCustXt.
 
1596
* KbdSetCp reverses the action of KbdSetCustXt and sets the handle equal to
 
1597
  one of the system translate tables. If memory is dynamically allocated by
 
1598
  the caller for the translate table and is freed before the KbdSetCp is
 
1599
  performed, KbdSetCp and future translations may fail.}
 
1600
function KbdSetCustXt(var XLateTbl:TXLateTbl;KbdHandle:word):word; cdecl;
 
1601
function KbdSetCustXt(var CodePage:word;KbdHandle:word):word; cdecl;
 
1602
function KbdSetCustXt(var XLateTblP:pointer;KbdHandle:word):word; cdecl;
 
1603
 
 
1604
 
 
1605
(* Following routines are not supported
 
1606
   (just have a look in some C header
 
1607
   file - you probably won't find it there either).
 
1608
KbdInit (index 2)
 
1609
KbdLoadInstance (index 6)
 
1610
KbdSwitchFgnd (index 15)
 
1611
KbdShellInit (index 16)
 
1612
KbdFree (index 19)
 
1613
*)
 
1614
 
 
1615
 
 
1616
{***************************************************************************}
 
1617
implementation
 
1618
{***************************************************************************}
 
1619
 
 
1620
 
 
1621
function KbdRegister(ModuleName,ProcName:PChar;FnMask:cardinal):word; cdecl;
 
1622
external 'EMXWRAP' index 208;
 
1623
{external 'KBDCALLS' index 8;}
 
1624
 
 
1625
function KbdRegister(ModuleName,ProcName:string;FnMask:cardinal):word;
 
1626
begin
 
1627
    if byte(ModuleName[0])>8 then byte(ModuleName[0]):=8;
 
1628
    ModuleName[Succ(byte(ModuleName[0]))]:=#0;
 
1629
    if byte(ProcName[0])>32 then byte(ProcName[0]):=32;
 
1630
    ProcName[Succ(byte(ProcName[0]))]:=#0;
 
1631
    KbdRegister:=KbdRegister(@ModuleName[1],@ProcName[1],FnMask);
 
1632
end;
 
1633
 
 
1634
function KbdDeRegister:word; cdecl;
 
1635
external 'EMXWRAP' index 220;
 
1636
{external 'KBDCALLS' index 20;}
 
1637
 
 
1638
function KbdCharIn(var Key:TKbdKeyInfo;WaitFlag,KbdHandle:word):word; cdecl;
 
1639
external 'EMXWRAP' index 204;
 
1640
{external 'KBDCALLS' index 4;}
 
1641
 
 
1642
function KbdPeek(var Key:TKbdKeyInfo;KbdHandle:word):word; cdecl;
 
1643
external 'EMXWRAP' index 222;
 
1644
{external 'KBDCALLS' index 22;}
 
1645
 
 
1646
function KbdStringIn(var CharBuf;var LenInOut:TStringInBuf;WaitFlag:word;
 
1647
                                                   KbdHandle:word):word; cdecl;
 
1648
external 'EMXWRAP' index 209;
 
1649
{external 'KBDCALLS' index 9;}
 
1650
 
 
1651
function KbdStringIn(CharBuf:PChar;LenInOutP:PStringInBuf;WaitFlag:word;
 
1652
                                                   KbdHandle:word):word; cdecl;
 
1653
external 'EMXWRAP' index 209;
 
1654
{external 'KBDCALLS' index 9;}
 
1655
 
 
1656
function KbdFlushBuffer(KbdHandle:word):word; cdecl;
 
1657
external 'EMXWRAP' index 213;
 
1658
{external 'KBDCALLS' index 13;}
 
1659
 
 
1660
function KbdSetStatus(var Status:TKbdInfo;KbdHandle:word):word; cdecl;
 
1661
external 'EMXWRAP' index 211;
 
1662
{external 'KBDCALLS' index 11;}
 
1663
 
 
1664
function KbdGetStatus(var Status:TKbdInfo;KbdHandle:word):word; cdecl;
 
1665
external 'EMXWRAP' index 210;
 
1666
{external 'KBDCALLS' index 10;}
 
1667
 
 
1668
function KbdSetCp(Reserved,CodePage,KbdHandle:word):word; cdecl;
 
1669
external 'EMXWRAP' index 205;
 
1670
{external 'KBDCALLS' index 5;}
 
1671
 
 
1672
function KbdGetCp(Reserved:cardinal;var CodePage:word;KbdHandle:word):word;
 
1673
                                                                         cdecl;
 
1674
external 'EMXWRAP' index 203;
 
1675
{external 'KBDCALLS' index 3;}
 
1676
 
 
1677
function KbdOpen(var KbdHandle:word):word; cdecl;
 
1678
external 'EMXWRAP' index 223;
 
1679
{external 'KBDCALLS' index 23;}
 
1680
 
 
1681
function KbdClose(KbdHandle:word):word; cdecl;
 
1682
external 'EMXWRAP' index 217;
 
1683
{external 'KBDCALLS' index 17;}
 
1684
 
 
1685
function KbdGetFocus(WaitFlag,KbdHandle:word):word; cdecl;
 
1686
external 'EMXWRAP' index 212;
 
1687
{external 'KBDCALLS' index 12;}
 
1688
 
 
1689
function KbdFreeFocus(KbdHandle:word):word; cdecl;
 
1690
external 'EMXWRAP' index 218;
 
1691
{external 'KBDCALLS' index 18;}
 
1692
 
 
1693
function KbdSynch (WaitFlag:word):word; cdecl;
 
1694
external 'EMXWRAP' index 207;
 
1695
{external 'KBDCALLS' index 7;}
 
1696
 
 
1697
function KbdSetFgnd:word; cdecl;
 
1698
external 'EMXWRAP' index 221;
 
1699
{external 'KBDCALLS' index 21;}
 
1700
 
 
1701
function KbdGetHWID(var HWID:TKbdHWID;KbdHandle:word):word; cdecl;
 
1702
external 'EMXWRAP' index 224;
 
1703
{external 'KBDCALLS' index 24;}
 
1704
 
 
1705
function KbdSetHWID(var HWID:TKbdHWID;KbdHandle:word):word; cdecl;
 
1706
external 'EMXWRAP' index 225;
 
1707
{external 'KBDCALLS' index 25;}
 
1708
 
 
1709
function KbdSetHWID(HWIDP:PKbdHWID;KbdHandle:word):word; cdecl;
 
1710
external 'EMXWRAP' index 225;
 
1711
{external 'KBDCALLS' index 25;}
 
1712
 
 
1713
function KbdXlate(var TransData:TKbdTrans;KbdHandle:word):word; cdecl;
 
1714
external 'EMXWRAP' index 214;
 
1715
{external 'KBDCALLS' index 14;}
 
1716
 
 
1717
function KbdSetCustXt(var XLateTbl:TXLateTbl;KbdHandle:word):word; cdecl;
 
1718
external 'EMXWRAP' index 201;
 
1719
{external 'KBDCALLS' index 1;}
 
1720
 
 
1721
function KbdSetCustXt(var CodePage:word;KbdHandle:word):word; cdecl;
 
1722
external 'EMXWRAP' index 201;
 
1723
{external 'KBDCALLS' index 1;}
 
1724
 
 
1725
function KbdSetCustXt(var XLateTblP:pointer;KbdHandle:word):word; cdecl;
 
1726
external 'EMXWRAP' index 201;
 
1727
{external 'KBDCALLS' index 1;}
 
1728
 
 
1729
 
 
1730
end.