keymap.pas 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. {
  2. This file is part of the Free Pascal run time library.
  3. A file in Amiga system run time library.
  4. Copyright (c) 1998-2003 by Nils Sjoholm
  5. member of the Amiga RTL development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {
  13. keymap.resource definitions and console.device key map definitions
  14. }
  15. {
  16. History:
  17. Added the defines use_amiga_smartlink and
  18. use_auto_openlib. Implemented autoopening
  19. of the library.
  20. 14 Jan 2003.
  21. Changed integer > smallint,
  22. cardinal > longword.
  23. 09 Feb 2003.
  24. [email protected] Nils Sjoholm
  25. }
  26. {$PACKRECORDS 2}
  27. {$IFNDEF FPC_DOTTEDUNITS}
  28. unit keymap;
  29. {$ENDIF FPC_DOTTEDUNITS}
  30. INTERFACE
  31. {$IFDEF FPC_DOTTEDUNITS}
  32. uses Amiga.Core.Exec, Amiga.Core.Inputevent;
  33. {$ELSE FPC_DOTTEDUNITS}
  34. uses exec, inputevent;
  35. {$ENDIF FPC_DOTTEDUNITS}
  36. Type
  37. pKeyMap = ^tKeyMap;
  38. tKeyMap = record
  39. km_LoKeyMapTypes : Pointer;
  40. km_LoKeyMap : Pointer;
  41. km_LoCapsable : Pointer;
  42. km_LoRepeatable : Pointer;
  43. km_HiKeyMapTypes : Pointer;
  44. km_HiKeyMap : Pointer;
  45. km_HiCapsable : Pointer;
  46. km_HiRepeatable : Pointer;
  47. end;
  48. pKeymapNode = ^tKeyMapNode;
  49. tKeyMapNode = record
  50. kn_Node : tNode; { including name of keymap }
  51. kn_KeyMap : tKeyMap;
  52. end;
  53. { the structure of keymap.resource }
  54. pKeyMapResource = ^tKeyMapResource;
  55. tKeyMapResource = record
  56. kr_Node : tNode;
  57. kr_List : tList; { a list of KeyMapNodes }
  58. end;
  59. Const
  60. { Key Map Types }
  61. KC_NOQUAL = 0;
  62. KC_VANILLA = 7; { note that SHIFT+ALT+CTRL is VANILLA }
  63. KCB_SHIFT = 0;
  64. KCF_SHIFT = $01;
  65. KCB_ALT = 1;
  66. KCF_ALT = $02;
  67. KCB_CONTROL = 2;
  68. KCF_CONTROL = $04;
  69. KCB_DOWNUP = 3;
  70. KCF_DOWNUP = $08;
  71. KCB_DEAD = 5; { may be dead or modified by dead key: }
  72. KCF_DEAD = $20; { use dead prefix bytes }
  73. KCB_STRING = 6;
  74. KCF_STRING = $40;
  75. KCB_NOP = 7;
  76. KCF_NOP = $80;
  77. { Dead Prefix Bytes }
  78. DPB_MOD = 0;
  79. DPF_MOD = $01;
  80. DPB_DEAD = 3;
  81. DPF_DEAD = $08;
  82. DP_2DINDEXMASK = $0f; { mask for index for 1st of two dead keys }
  83. DP_2DFACSHIFT = 4; { shift for factor for 1st of two dead keys }
  84. VAR KeymapBase : pLibrary = nil;
  85. const
  86. KEYMAPNAME : PAnsiChar = 'keymap.library';
  87. {$if defined(AMIGA_V1_2_ONLY)}
  88. function MapRawKey(event: PInputEvent; Buffer: PAnsiChar; Length: LongInt; keyMap: PKeyMap): SmallInt;
  89. {$else}
  90. FUNCTION AskKeyMapDefault : pKeyMap; syscall KeymapBase 036;
  91. FUNCTION MapANSI(thestring : PAnsiChar location 'a0'; count : LONGINT location 'd0'; buffer : PAnsiChar location 'a1'; length : LONGINT location 'd1'; keyMap : pKeyMap location 'a2') : LONGINT; syscall KeymapBase 048;
  92. FUNCTION MapRawKey(event : pInputEvent location 'a0'; buffer : PAnsiChar location 'a1'; length : LONGINT location 'd1'; keyMap : pKeyMap location 'a2') : smallint; syscall KeymapBase 042;
  93. PROCEDURE SetKeyMapDefault(keyMap : pKeyMap location 'a0'); syscall KeymapBase 030;
  94. {$endif}
  95. IMPLEMENTATION
  96. {$if defined(AMIGA_V1_2_ONLY)}
  97. var
  98. ConDev: PDevice = nil;
  99. ConMsgPort: PMsgPort = nil;
  100. ConIOReq: PIORequest = nil;
  101. function RawKeyConvert(Events: PInputEvent location 'a0'; Buffer: PAnsiChar location 'a1'; Length: LongInt location 'd1'; KeyMap: PKeyMap location 'a2'): LongInt; syscall ConDev 048;
  102. function MapRawKey(event: PInputEvent; Buffer: PAnsiChar; Length: LongInt; keyMap: PKeyMap): SmallInt;
  103. begin
  104. if not Assigned(ConDev) then
  105. begin
  106. ConMsgPort := CreatePort(nil, 0);
  107. ConIOReq := CreateExtIO(ConMsgPort, SizeOf(TIOStdReq));
  108. OpenDevice('console.device', -1, ConIOReq, 0);
  109. ConDev := ConIOReq^.io_Device;
  110. end;
  111. if Assigned(ConDev) then
  112. MapRawKey := RawKeyConvert(event, Buffer, length, keymap)
  113. else
  114. MapRawKey := 0;
  115. end;
  116. procedure CloseKeyMapConsole;
  117. begin
  118. if Assigned(ConDev) and Assigned(ConIOReq) then
  119. begin
  120. CloseDevice(ConIOReq);
  121. DeleteExtIO(ConIOReq);
  122. end;
  123. ConDev := nil;
  124. ConIOReq := nil;
  125. if Assigned(ConMsgPort) then
  126. DeletePort(ConMsgPort);
  127. ConMsgPort := nil;
  128. end;
  129. {$endif}
  130. const
  131. { Change VERSION and LIBVERSION to proper values }
  132. VERSION : string[2] = '0';
  133. LIBVERSION : longword = 0;
  134. initialization
  135. KeymapBase := OpenLibrary(KEYMAPNAME,LIBVERSION);
  136. finalization
  137. if Assigned(KeymapBase) then
  138. CloseLibrary(KeymapBase);
  139. {$if defined(AMIGA_V1_2_ONLY)}
  140. CloseKeyMapConsole;
  141. {$endif}
  142. END. (* UNIT KEYMAP *)