testkbd.pas 842 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. program TestKBD;
  2. {$X+}
  3. {$IFNDEF OS2}
  4. Sorry, this code is for OS/2 only...
  5. {$ENDIF}
  6. uses
  7. {$IFDEF FPC}
  8. KbdCalls;
  9. {$ELSE}
  10. {$IFDEF SPEED}
  11. BseSub;
  12. {$ELSE}
  13. Os2Subs;
  14. {$ENDIF}
  15. {$ENDIF}
  16. function ExtKeyPressed: boolean; (* 'key' is here as well e.g. a shift *)
  17. var
  18. {$IFNDEF VER70} (* patched Borland Pascal *)
  19. KI: KbdKeyInfo;
  20. K: KbdInfo;
  21. {$ELSE}
  22. KI: TKbdKeyInfo;
  23. K: TKbdInfo;
  24. {$ENDIF}
  25. B: boolean;
  26. begin
  27. B := false;
  28. K.cb := SizeOf (K);
  29. KbdGetStatus (K, 0);
  30. KbdPeek (KI, 0);
  31. if (KI.fbStatus and $FE <> 0) or (K.fsState and $FF0F <> 0) then
  32. begin
  33. ExtKeyPressed := true;
  34. if KI.fbStatus and $FE <> 0 then KbdCharIn (KI, IO_NOWAIT, 0);
  35. end else ExtKeyPressed := false;
  36. end;
  37. begin
  38. repeat until not (ExtKeyPressed);
  39. WriteLn (#13#10'Press _any_ key to continue (including shifts etc.) ...');
  40. repeat until ExtKeyPressed;
  41. end.