does not go inside the Windows GetMessage loop on console application

前端 未结 2 597
你的背包
你的背包 2021-01-28 01:32

I want to detect keypress in C++ and i need to use Windows System Call. So, i did some research and this is what i got using Hooks and Message:

#include 

        
2条回答
  •  灰色年华
    2021-01-28 02:01

    That's not surprising, there aren't really any messages on your thread queue and you have no window so there's no window queue either.

    If you want to play with values returned from your hook, put the code in the hook callback function.

    I should warn you that hooks like these won't work in console applications since the console window resides in another process. Also, if you look at the MSDN page for SetWindowsHookEx, you'll see that WH_KEYBOARD_LL is a global hook only, ie you have to put your hook handler in a DLL library and inject the hook in the other applications. Then you have to handle the 32/64 bit issue yourself.

    And as a last note, when you say cout << c; in your handler, that would be printing in the process's output file handle, not your own.

提交回复
热议问题