/components/mouseandkeyinput/winkeyinput.pas

http://github.com/graemeg/lazarus · Pascal · 73 lines · 37 code · 17 blank · 19 comment · 0 complexity · 990f59bdfb43e4d04f055c76e2219e95 MD5 · raw file

  1. { WinKeyInput
  2. Copyright (C) 2008 Tom Gregorovic
  3. This source is free software; you can redistribute it and/or modify it under the terms of the
  4. GNU General Public License as published by the Free Software Foundation; either version 2 of the
  5. License, or (at your option) any later version.
  6. This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  7. even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  8. General Public License for more details.
  9. A copy of the GNU General Public License is available on the World Wide Web at
  10. <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing to the Free Software
  11. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  12. }
  13. unit WinKeyInput;
  14. {$mode objfpc}{$H+}
  15. interface
  16. uses
  17. Classes, SysUtils, Controls, Forms,
  18. Windows, JwaWinUser,
  19. KeyInputIntf;
  20. type
  21. { TWinKeyInput }
  22. TWinKeyInput = class(TKeyInput)
  23. protected
  24. procedure DoDown(Key: Word); override;
  25. procedure DoUp(Key: Word); override;
  26. end;
  27. function InitializeKeyInput: TKeyInput;
  28. implementation
  29. function InitializeKeyInput: TKeyInput;
  30. begin
  31. Result := TWinKeyInput.Create;
  32. end;
  33. procedure SendKeyInput(Flag: DWORD; Key: Word);
  34. var
  35. Input: TInput;
  36. begin
  37. FillChar(Input, SizeOf(Input), 0);
  38. Input.type_ := INPUT_KEYBOARD;
  39. Input.ki.dwFlags := Flag;
  40. Input.ki.wVk := Key;
  41. SendInput(1, @Input, SizeOf(Input));
  42. end;
  43. { TWinKeyInput }
  44. procedure TWinKeyInput.DoDown(Key: Word);
  45. begin
  46. SendKeyInput(0, Key);
  47. end;
  48. procedure TWinKeyInput.DoUp(Key: Word);
  49. begin
  50. SendKeyInput(KEYEVENTF_KEYUP, Key);
  51. end;
  52. end.