Results 1 to 2 of 2

Thread: Key trapping

  1. #1

    Key trapping

    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
    Live programming, eat programming, breath programming and die programming

  2. #2

    Re: Key trapping

    Not sure what you mean, can you expain more?

    Maybe something like this?

    [pascal]procedure TFormGame.FormKeyDown(Sender: TObject; var Key: Word;
    Shift: TShiftState);
    begin
    if key = vk_Escape then
    application.Terminate;
    end;[/pascal]

    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 :

    [pascal]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';
    [/pascal]
    Wake up from the dream and live your life to the full

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •