keyboard.pp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Florian Klaempfl
  4. member of the Free Pascal development team
  5. Keyboard unit for MS-DOS
  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. unit Keyboard;
  13. interface
  14. {$i keybrdh.inc}
  15. implementation
  16. uses
  17. dos;
  18. {$i keyboard.inc}
  19. var
  20. keyboard_type: byte; { 0=83/84-key keyboard, $10=101/102+ keyboard }
  21. procedure SysInitKeyboard;
  22. var
  23. regs: registers;
  24. begin
  25. keyboard_type:=0;
  26. if (Mem[$40:$96] and $10)<>0 then
  27. begin
  28. regs.ax:=$1200;
  29. intr($16,regs);
  30. if regs.ax<>$1200 then
  31. keyboard_type:=$10;
  32. end;
  33. end;
  34. function SysGetKeyEvent: TKeyEvent;
  35. var
  36. regs : registers;
  37. begin
  38. regs.ah:=keyboard_type;
  39. intr($16,regs);
  40. if (regs.al=$e0) and (regs.ah<>0) then
  41. regs.al:=0;
  42. SysGetKeyEvent:=(kbPhys shl 24) or regs.ax or ((mem[$40:$17] and $f) shl 16);
  43. end;
  44. function SysPollKeyEvent: TKeyEvent;
  45. var
  46. regs : registers;
  47. begin
  48. regs.ah:=keyboard_type+1;
  49. intr($16,regs);
  50. if (regs.flags and fzero)<>0 then
  51. exit(0);
  52. if (regs.al=$e0) and (regs.ah<>0) then
  53. regs.al:=0;
  54. SysPollKeyEvent:=(kbPhys shl 24) or regs.ax or ((mem[$40:$17] and $f) shl 16);
  55. end;
  56. function SysGetShiftState: Byte;
  57. begin
  58. SysGetShiftState:=(mem[$40:$17] and $f);
  59. end;
  60. Const
  61. SysKeyboardDriver : TKeyboardDriver = (
  62. InitDriver : @SysInitKeyboard;
  63. DoneDriver : Nil;
  64. GetKeyevent : @SysGetKeyEvent;
  65. PollKeyEvent : @SysPollKeyEvent;
  66. GetShiftState : @SysGetShiftState;
  67. TranslateKeyEvent : Nil;
  68. TranslateKeyEventUnicode : Nil;
  69. );
  70. begin
  71. SetKeyBoardDriver(SysKeyBoardDriver);
  72. end.