View Full Version : Key trapping
yassersoft
29-04-2009, 05:40 PM
I want to male an application in delphi that scan when I press a predefined key from the keyboard. I´m don´t mean use the Hook function. On C++ i do it this way:
#define Function_Name ((GetAsyncKey // I don´t remeber all.. I just copy paste
I want to know the equivalence for delphi
Wizard
29-04-2009, 05:58 PM
Not sure what you mean, can you expain more?
Maybe something like this?
procedure TFormGame.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = vk_Escape then
application.Terminate;
end;
Where vk can be any of the following:
{ Virtual Keys, Standard Set }
{$EXTERNALSYM VK_LBUTTON}
VK_LBUTTON = 1;
{$EXTERNALSYM VK_RBUTTON}
VK_RBUTTON = 2;
{$EXTERNALSYM VK_CANCEL}
VK_CANCEL = 3;
{$EXTERNALSYM VK_MBUTTON}
VK_MBUTTON = 4; { NOT contiguous with L & RBUTTON }
{$EXTERNALSYM VK_BACK}
VK_BACK = 8;
{$EXTERNALSYM VK_TAB}
VK_TAB = 9;
{$EXTERNALSYM VK_CLEAR}
VK_CLEAR = 12;
{$EXTERNALSYM VK_RETURN}
VK_RETURN = 13;
{$EXTERNALSYM VK_SHIFT}
VK_SHIFT = $10;
{$EXTERNALSYM VK_CONTROL}
VK_CONTROL = 17;
{$EXTERNALSYM VK_MENU}
VK_MENU = 18;
{$EXTERNALSYM VK_PAUSE}
VK_PAUSE = 19;
Etc.
Or :
procedure TForm1.Button1Click(Sender: TObject);
var
hTaskBar : THandle;
begin
// If you want to detect a letter you must use the ascii code.
//detect the "a and the A letter".
if GetasyncKeyState(65)<>0 then Caption:='A';
if GetasyncKeyState(97)<>0 then Caption:='a';
// If you want to detect the left button of the mouse use:
if GetasyncKeyState(1)<>0 'mouse
end;
//To detect a key you must use the Virtual key codes..
if GetasyncKeyState(vk_space)<>0 then Caption:='Spacebar';
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.