keymap.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2007 by Karoly Balogh
  4. keymap.library interface unit for MorphOS/PowerPC
  5. Based on the Commodore Amiga/68k port by Nils Sjoholm
  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. {$PACKRECORDS 2}
  13. unit keymap;
  14. INTERFACE
  15. uses exec, inputevent;
  16. Type
  17. pKeyMap = ^tKeyMap;
  18. tKeyMap = record
  19. km_LoKeyMapTypes : Pointer;
  20. km_LoKeyMap : Pointer;
  21. km_LoCapsable : Pointer;
  22. km_LoRepeatable : Pointer;
  23. km_HiKeyMapTypes : Pointer;
  24. km_HiKeyMap : Pointer;
  25. km_HiCapsable : Pointer;
  26. km_HiRepeatable : Pointer;
  27. end;
  28. pKeymapNode = ^tKeyMapNode;
  29. tKeyMapNode = record
  30. kn_Node : tNode; { including name of keymap }
  31. kn_KeyMap : tKeyMap;
  32. end;
  33. { the structure of keymap.resource }
  34. pKeyMapResource = ^tKeyMapResource;
  35. tKeyMapResource = record
  36. kr_Node : tNode;
  37. kr_List : tList; { a list of KeyMapNodes }
  38. end;
  39. Const
  40. { Key Map Types }
  41. KC_NOQUAL = 0;
  42. KC_VANILLA = 7; { note that SHIFT+ALT+CTRL is VANILLA }
  43. KCB_SHIFT = 0;
  44. KCF_SHIFT = $01;
  45. KCB_ALT = 1;
  46. KCF_ALT = $02;
  47. KCB_CONTROL = 2;
  48. KCF_CONTROL = $04;
  49. KCB_DOWNUP = 3;
  50. KCF_DOWNUP = $08;
  51. KCB_DEAD = 5; { may be dead or modified by dead key: }
  52. KCF_DEAD = $20; { use dead prefix bytes }
  53. KCB_STRING = 6;
  54. KCF_STRING = $40;
  55. KCB_NOP = 7;
  56. KCF_NOP = $80;
  57. { Dead Prefix Bytes }
  58. DPB_MOD = 0;
  59. DPF_MOD = $01;
  60. DPB_DEAD = 3;
  61. DPF_DEAD = $08;
  62. DP_2DINDEXMASK = $0f; { mask for index for 1st of two dead keys }
  63. DP_2DFACSHIFT = 4; { shift for factor for 1st of two dead keys }
  64. var
  65. KeymapBase : pLibrary;
  66. const
  67. KEYMAPNAME : PChar = 'keymap.library';
  68. procedure SetKeyMapDefault(CONST keyMap : pKeyMap location 'a0');
  69. SysCall KeymapBase 030;
  70. function AskKeyMapDefault : pKeyMap;
  71. SysCall KeymapBase 036;
  72. function MapRawKey(CONST event : pInputEvent location 'a0'; buffer : pSHORTINT location 'a1'; length : longint location 'd1'; CONST keyMap : pKeyMap location 'a2') : INTEGER;
  73. SysCall KeymapBase 042;
  74. function MapANSI(CONST strg : pSHORTINT location 'a0'; count : longint location 'd0'; buffer : pSHORTINT location 'a1'; length : longint location 'd1'; CONST keyMap : pKeyMap location 'a2') : longint;
  75. SysCall KeymapBase 048;
  76. { Helper calls }
  77. function InitKeymapLibrary : boolean;
  78. implementation
  79. const
  80. { Change VERSION and LIBVERSION to proper values }
  81. VERSION : string[2] = '50';
  82. LIBVERSION : longword = 50;
  83. var
  84. keymap_exit : Pointer;
  85. procedure CloseKeymapLibrary;
  86. begin
  87. ExitProc := keymap_exit;
  88. if KeymapBase <> nil then begin
  89. CloseLibrary(PLibrary(KeymapBase));
  90. KeymapBase := nil;
  91. end;
  92. end;
  93. function InitKeymapLibrary : boolean;
  94. begin
  95. KeymapBase := nil;
  96. KeymapBase := OpenLibrary(KEYMAPNAME,LIBVERSION);
  97. if KeymapBase <> nil then begin
  98. keymap_exit := ExitProc;
  99. ExitProc := @CloseKeymapLibrary;
  100. InitKeymapLibrary:=True;
  101. end else begin
  102. InitKeymapLibrary:=False;
  103. end;
  104. end;
  105. end.