[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: w32-pass-lwindow-to-system does not work as expected

From: Lennart Borgman
Subject: Re: w32-pass-lwindow-to-system does not work as expected
Date: Wed, 06 Jul 2005 00:43:12 +0200
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Eli Zaretskii wrote:

Watch out for the caveats of using low-level keyboard interfaces: what
the hook gets is the scan code of the key and various bit masks for ...
I took a look at the code in w32fns.c again. It looks to me everything is in place to handle the <lwindow> key, except for that low level keyboard hook. Everything the keyboard hook has to to is to avoid sending anything to the system when <lwindow> is typed and Emacs wants it.

So if it works at all it should perhaps be very little trouble:

1) add the hook at thread startup
2) the hook prevents sending any VK_LWIN events further if Emacs wants them, otherwise not.
3) remove the hook at thread termination.

Below is code for doing this. I have assumed that NILP and Vw32_pass_lwindow_to_system are actually available in the input thread. (Or did I read that wrong?)

But as I said I am not a guru on this, I just read the docs and the code. Am I misunderstanding something here?

*** Adding the low level keyboard hook to the main thread at thread startup:
hLowKBhook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, NULL, 

*** Removing the low level keyboard hook at the main thread tear down:

*** The hook procedure. This runs in the context of the thread.

LRESULT LowLevelKeyboardProc(INT nCode, WPARAM wParam, LPARAM lParam)
   BOOL fHandled = FALSE;

   if (nCode == HC_ACTION)
       KBDLLHOOKSTRUCT *pkbdllhook = (KBDLLHOOKSTRUCT *)lParam;

       switch (wParam)
           case WM_KEYUP:
           case WM_KEYDOWN:  // This was not in the MS example, why??
           case WM_SYSKEYUP:
           case WM_SYSKEYDOWN:
               switch (pkbdllhook->vkCode)
                   case VK_LWIN:
                       // the user pressed the <lwindow> key
                if (!NILP (Vw32_pass_lwindow_to_system))
                       fHandled = TRUE;

   return (fHandled ? TRUE : CallNextHookEx(hhook, nCode, wParam, lParam));

reply via email to

[Prev in Thread] Current Thread [Next in Thread]