home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Softwarová Záchrana 3
/
Softwarova-zachrana-3.bin
/
ArsClip
/
source.zip
/
UnitKeyboardQuery.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2003-07-30
|
2KB
|
102 lines
unit UnitKeyboardQuery;
{
Purpose:
Query if a key is pressed or a lock key is on/off
Updates:
- new functionality
- Mouse clickes added
NOTES:
Mouse clicks may not seem like a Keyboard function, but
they are retreived from GetAsyncKeyState
}
{///////////}
{}interface{}
{///////////}
uses Windows, Dialogs, SysUtils;
type MouseButton = (leftButton, RightButton);
type TKeyboardQuery = class(TObject)
private
public
function IsPressed(VKConstant : integer) : boolean;
function LockOn(VKConstant : integer) : boolean;
procedure WaitUntilRelease(VKConstant : integer); overload;
procedure WaitUntilRelease(bi : MouseButton); overload;
function IsClicked( bi : MouseButton ) : boolean;
end;
var KeyboardQuery : TKeyboardQuery;
{////////////////}
{}implementation{}
{////////////////}
uses Forms;
function TKeyboardQuery.IsClicked( bi : MouseButton ) : boolean;
var VK : integer;
begin
Windows.SetLastError(ERROR_SUCCESS);
//
// The Physical and Logical "Left Button" may not be the same
//
if (bi = LeftButton) and
(GetSystemMetrics(SM_SWAPBUTTON) = 0) then begin
vk := VK_LBUTTON;
end else begin
vk := VK_RBUTTON;
end;
result := (Windows.GetAsyncKeyState(vk) and $8000) > 0;
end;
function TKeyboardQuery.IsPressed(VKConstant : integer) : boolean;
begin
Windows.SetLastError(ERROR_SUCCESS);
result := (Windows.GetKeyState(VKConstant) and 128) <> 0;
end;
function TKeyboardQuery.LockOn(VKConstant : integer) : boolean;
begin
Windows.SetLastError(ERROR_SUCCESS);
result := (Windows.GetKeyState(VKConstant) and 1) <> 0;
end;
procedure TKeyboardQuery.WaitUntilRelease(VKConstant: integer);
begin
While self.IsPressed(VKConstant) do begin
Application.ProcessMessages;
end;
end;
procedure TKeyboardQuery.WaitUntilRelease(bi: MouseButton);
begin
while IsClicked(bi) do begin
Application.ProcessMessages;
end;
end;
{////////////////}
{}initialization{}
{////////////////}
Begin
KeyboardQuery := TKeyboardQuery.Create;
end;
end.