PageRenderTime 17ms CodeModel.GetById 11ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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