Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /home/iano/public_html/tpforums-vb5/forum/includes/class_core.php on line 5842

PHP Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_BOTH - assumed 'MYSQL_BOTH' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 588

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 612

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6
How to write a simple Keyboard hook - Page 2
Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: How to write a simple Keyboard hook

  1. #11
    Junior Member
    Join Date
    Jun 2007
    Posts
    15

    How to write a simple Keyboard hook

    Great tutorial, well written!

  2. #12

    How to write a simple Keyboard hook

    Why "KeyboardProc@12" and not "KeyboardProc" ?

    TY

  3. #13

    How to write a simple Keyboard hook

    Gratz on your nice article Kekke, I'll talk to ya soon

    Sokz

  4. #14

    How to write a simple Keyboard hook

    But, how to communicate with your program telling that a key was pressed?

  5. #15

    How to write a simple Keyboard hook

    amazing tutorial, big gratz, I 'm waiting for next

  6. #16

    How to write a simple Keyboard hook

    Quote Originally Posted by Bruno
    Why "KeyboardProc@12" and not "KeyboardProc" ?

    TY
    Normally in std calls windows symbols require the "@" and the amount of bytes the parameters take (so imagine you have one byte param and 2 int params, that gives you 9, thus FunctionName@9)
    [align=center]\"12:16 You lose your virginity due to an attack by Michael Jackson.\" RIP Jacko.
    Join TProgramming secure chat room!
    http://www.afternet.org/afternet_sta...=GUSHH&small=1[/align]

  7. #17
    Junior Member
    Join Date
    May 2009
    Posts
    1

    RE: How to write a simple Keyboard hook

    This won't work. Windows applications usually have several threads. You need to hook thread that has created main window. With this method you don't know what thread you have found. You know only that thread is connected with your process id. Finding right thread is simpler than you think. You used GetWindowThreadProcessId() function and you hasn't looked at msdn?

    Return Value

    DWORD

    The return value is the identifier of the thread that created the window.
    That's right thread .

    Now all should be like that.
    [code=cpp]
    #include <windows.h>

    int main(int argc, char *argv[])
    {
    DWORD dwThreadId = 0;
    DWORD dwProcessId = 0;
    HWND hTibiaWnd = 0;
    HINSTANCE hDll = 0;
    HOOKPROC KeyboardProc = 0;
    HHOOK hHook = 0;

    hTibiaWnd = FindWindow(0, "Tibia");
    if (!hTibiaWnd)
    {
    // Do something
    return 0;
    }

    dwThreadId = GetWindowThreadProcessId(hTibiaWnd, &dwProcessId);
    if (!dwThreadId)
    {
    // Do something
    return 0;
    }

    hDll = LoadLibrary("Keyboardhooktest.dll");
    if (!hDll)
    {
    // Do something
    return 0;
    }

    KeyboardProc = reinterpret_cast<HOOKPROC>(GetProcAddress(hDll, "KeyboardProc@12"));
    if (!KeyboardProc)
    {
    // Do something
    return 0;
    }

    hHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, hDll, dwThreadId);
    if (!hHook)
    {
    // Do something
    return 0;
    }

    system("pause");

    UnhookWindowsHookEx(hHook);
    FreeLibrary(hDll);

    return 0;
    }
    [/code]
    This is simpler, faster and wil work .

    If somebody has problem with "KeyboardProc@12" try "_KeyboardProc@12". Anyway look at exports library file. There you will find name of your function.

Posting Permissions

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