From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lennart Borgman Newsgroups: gmane.emacs.devel Subject: Re: w32-pass-lwindow-to-system does not work as expected Date: Wed, 06 Jul 2005 00:43:12 +0200 Message-ID: <42CB0D00.3030900@student.lu.se> References: <42CADC1A.4060106@student.lu.se> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1120603798 21445 80.91.229.2 (5 Jul 2005 22:49:58 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 5 Jul 2005 22:49:58 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jul 06 00:49:50 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DpwEO-0002Uz-3U for ged-emacs-devel@m.gmane.org; Wed, 06 Jul 2005 00:49:32 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DpwFf-0005Ph-Gi for ged-emacs-devel@m.gmane.org; Tue, 05 Jul 2005 18:50:51 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DpwFD-00057k-AT for emacs-devel@gnu.org; Tue, 05 Jul 2005 18:50:23 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DpwF5-00053a-Ie for emacs-devel@gnu.org; Tue, 05 Jul 2005 18:50:18 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DpwF4-0004wv-GM for emacs-devel@gnu.org; Tue, 05 Jul 2005 18:50:14 -0400 Original-Received: from [81.228.8.83] (helo=pne-smtpout1-sn2.hy.skanova.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DpwER-0006q7-9B; Tue, 05 Jul 2005 18:49:35 -0400 Original-Received: from [192.168.123.121] (83.249.205.6) by pne-smtpout1-sn2.hy.skanova.net (7.2.060.1) id 42BFBBD2001A80D5; Wed, 6 Jul 2005 00:43:16 +0200 User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en Original-To: Eli Zaretskii In-Reply-To: X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:40474 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:40474 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 key, except for that low level keyboard hook. Everything the keyboard hook has to to is to avoid sending anything to the system when 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, dwMainThreadId); *** Removing the low level keyboard hook at the main thread tear down: UnhookWindowsHookEx(hLowKBhook); *** 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 key if (!NILP (Vw32_pass_lwindow_to_system)) fHandled = TRUE; break; } } } } return (fHandled ? TRUE : CallNextHookEx(hhook, nCode, wParam, lParam)); }