WH_KEYBOARD_LL vs GetKeyState

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
jürgen urner
Newbie
Newbie
Posts: 2
Joined: Wed Aug 05, 2009 12:13 pm

WH_KEYBOARD_LL vs GetKeyState

Post by jürgen urner »

hi all,

i have problems running this code (taken from: http://blogs.msdn.com/michkap/archive/2 ... 32470.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: Select all

#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;





vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: WH_KEYBOARD_LL vs GetKeyState

Post by vitamin »

jürgen urner wrote:the GetKeyState trick is not working
It does, only if Wine's window has focus. Wine does not capture all keyboard events that happen system wide.
Locked