deadkeys.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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-2002 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. DeadKeyConvert
  14. When you want Intuition to send you keystrokes, you either get just
  15. the simple key-cap type keys (i.e. no cursor or function keys) or you
  16. get keycodes, which tell you nothing about what was on the key the
  17. user pressed. DeadKeyConvert allows you to receive RAWKEY messages,
  18. then translate them into their ANSI key sequences. These are known as
  19. cooked keys, and a single keystroke might be converted into as many as
  20. four characters (including the CSI). See the ROM Kernel Manual and the
  21. Enhancer manual for details.
  22. The difference between this and RawKeyConvert is that this also
  23. handles the deadkeys - for example, pressing ALT-K, releasing it, and
  24. pressing o gives you an o with an umlaut.
  25. Also note that some keys will come back with a length of zero - the
  26. shift and alt keys, for example. You can probably ignore them.
  27. Finally, I'll point out that, since this function calls RawKeyConvert,
  28. you need to call OpenConsoleDevice (defined in ConsoleUtils) before using
  29. it.
  30. }
  31. {
  32. History:
  33. A translation of DeadKeyConvert.p from PCQ Pascal.
  34. 26 Aug 2000.
  35. [email protected]
  36. }
  37. unit deadkeys;
  38. interface
  39. uses exec,intuition,console,inputevent;
  40. function DeadKeyConvert(msg : pIntuiMessage; buffer : pchar;
  41. bufsize : longint; keymap : pointer): longint;
  42. implementation
  43. function DeadKeyConvert(msg : pIntuiMessage; buffer : pchar;
  44. bufsize : longint; keymap : pointer): longint;
  45. var
  46. theevent : tInputEvent;
  47. Temp : ^pointer;
  48. begin
  49. if msg^.IClass <> IDCMP_RAWKEY then
  50. DeadKeyConvert := -2;
  51. with theevent do begin
  52. ie_NextEvent := nil;
  53. ie_Class := IECLASS_RAWKEY;
  54. ie_SubClass := 0;
  55. ie_Code := msg^.Code;
  56. ie_Qualifier := msg^.Qualifier;
  57. Temp := msg^.IAddress;
  58. ie_position.ie_addr := Temp^;
  59. end;
  60. DeadKeyConvert := RawKeyConvert(Addr(theevent),buffer,bufsize,keymap);
  61. end;
  62. var
  63. my_exit : pointer;
  64. ConsoleRequest : tIOStdReq;
  65. procedure CloseConsoleDevice;
  66. begin
  67. CloseDevice(Addr(ConsoleRequest));
  68. end;
  69. begin
  70. ConsoleDevice := nil;
  71. OpenDevice(pchar('console.device'#0),-1,Addr(ConsoleRequest),0);
  72. ConsoleDevice := ConsoleRequest.io_Device;
  73. my_exit := ExitProc;
  74. ExitProc := @CloseConsoleDevice;
  75. end.