[Wine] WH_KEYBOARD_LL vs GetKeyState

jürgen urner wineforum-user at winehq.org
Thu Aug 6 02:49:19 CDT 2009


hi all,

i have problems running this code (taken from: http://blogs.msdn.com/michkap/archive/2006/12/20/1332470.aspx) in wine (1.1.26). the GetKeyState trick is not working, so GetKeyboardState never fills in any information in windowless apps.                             
 




> /*
>          * If this thread needs a key state event, give one to it. There are
>          * cases where any app may be looping looking at GetKeyState(), plus
>          * calling PeekMessage(). Key state events don't get created unless
>          * new hardware input comes along. If the app isn't receiving hardware
>          * input, it won't get the new key state. So ResyncKeyState() will
>          * ensure that if the app is looping on GetKeyState(), it'll get the
>          * right key state.
>          */





Code:
#include <windows.h>
#include <cstdio>

LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM
lParam) {
    if(nCode == HC_ACTION && wParam == WM_KEYDOWN) {
        KBDLLHOOKSTRUCT* key = (KBDLLHOOKSTRUCT*)lParam;

        GetKeyState(0);

        BYTE keyState[256];

        GetKeyboardState(keyState);

        WORD chars;

        if(ToAscii(key->vkCode, key->scanCode, keyState, &chars, 0)) {
            if((char)chars == '\r') putchar('\n');
            else putchar(chars);
        }
    }

    return CallNextHookEx(NULL, nCode, wParam, lParam);
}

int main(int argc, char** argv) {
    HHOOK hhk = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc,
GetModuleHandle(NULL), 0);

    MSG msg;

    while(GetMessage(&msg, NULL, 0, 0) > 0);

    UnhookWindowsHookEx(hhk);

    return 0;















More information about the wine-users mailing list