public inbox for cygwin-xfree@sourceware.org
help / color / mirror / Atom feed
* considering modifier keys after gaining focus
@ 2011-08-16 15:31 Oliver Schmidt
  2011-08-21  8:44 ` Corinna Vinschen
  2012-01-08 15:23 ` Oliver Schmidt
  0 siblings, 2 replies; 11+ messages in thread
From: Oliver Schmidt @ 2011-08-16 15:31 UTC (permalink / raw)
  To: cygwin-xfree

[-- Attachment #1: Type: text/plain, Size: 1076 bytes --]

Hi,

I had the problem, that the state of the modifier keys was lost when a 
window is created (or raised).

Example: in window A Ctrl + some key opens a window B, then in window B 
Ctrl + some other key triggers the next action. However after the 
opening of window B the Ctrl key has to be released and pressed again. 
If the user keeps the Ctrl key holding when the window B is opened, the 
next key press X will be interpreted as X and not as Ctrl+X.

I send a patch to fix this problem with this email: I just extended the 
function winRestoreModeKeyStates in winkeybd.c to consider not only the 
mode switch key but also the modifiers Ctrl, Shift, Alt/AltGr by using 
the Windows function GetAsyncKeyState.

This patch works fine for me.

However one problem is unsolved: if the key combination for opening 
window B (in the above example) is an AltGr key combination, the 
GetAsyncKeyState will also report, that the Ctrl key is pressed, which 
is not true, since this is the well known Windows fake Ctrl_L :-(

Any suggestions how to solve this?

Best regards,
Oliver

[-- Attachment #2: diff03.txt --]
[-- Type: text/plain, Size: 1675 bytes --]

diff --git a/cygwin/hw/xwin/winkeybd.c b/cygwin/hw/xwin/winkeybd.c
index 9e5a9b0..e807fc5 100644
--- a/cygwin/hw/xwin/winkeybd.c
+++ b/cygwin/hw/xwin/winkeybd.c
@@ -255,6 +255,7 @@ void
 winRestoreModeKeyStates (void)
 {
   DWORD			dwKeyState;
+  BOOL			modifierPressed;
   BOOL			processEvents = TRUE;
   unsigned short	internalKeyStates;
 
@@ -282,6 +283,34 @@ winRestoreModeKeyStates (void)
    * have a logical XOR operator, so we use a macro instead.
    */
 
+  modifierPressed = (GetAsyncKeyState (VK_CONTROL) < 0);
+  if (WIN_XOR (internalKeyStates & ControlMask, modifierPressed))
+    {
+      if (modifierPressed) winSendKeyEvent (KEY_LCtrl, TRUE);
+      else                 winSendKeyEvent (KEY_LCtrl, FALSE);
+    }
+
+  modifierPressed = (GetAsyncKeyState (VK_SHIFT) < 0);
+  if (WIN_XOR (internalKeyStates & ShiftMask, modifierPressed))
+    {
+      if (modifierPressed) winSendKeyEvent (KEY_ShiftL, TRUE);
+      else                 winSendKeyEvent (KEY_ShiftL, FALSE);
+    }
+
+  modifierPressed = (GetAsyncKeyState (VK_LMENU) < 0);
+  if (WIN_XOR (internalKeyStates & Mod1Mask, modifierPressed))
+    {
+      if (modifierPressed) winSendKeyEvent (KEY_Alt, TRUE);
+      else                 winSendKeyEvent (KEY_Alt, FALSE);
+    }
+
+  modifierPressed = (GetAsyncKeyState (VK_RMENU) < 0);
+  if (WIN_XOR (internalKeyStates & Mod5Mask, modifierPressed))
+    {
+      if (modifierPressed) winSendKeyEvent (KEY_AltLang, TRUE);
+      else                 winSendKeyEvent (KEY_AltLang, FALSE);
+    }
+
   /* Has the key state changed? */
   dwKeyState = GetKeyState (VK_NUMLOCK) & 0x0001;
   if (WIN_XOR (internalKeyStates & NumLockMask, dwKeyState))


[-- Attachment #3: Type: text/plain, Size: 223 bytes --]

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-01-12 12:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-16 15:31 considering modifier keys after gaining focus Oliver Schmidt
2011-08-21  8:44 ` Corinna Vinschen
2011-08-21 10:04   ` Oliver Schmidt
2012-01-08 15:23 ` Oliver Schmidt
2012-01-09 14:06   ` Jon TURNEY
2012-01-09 18:11     ` Oliver Schmidt
2012-01-10  9:47       ` Oliver Schmidt
2012-01-10 10:15         ` Oliver Schmidt
2012-01-11 17:16       ` Jon TURNEY
2012-01-12 12:19         ` Oliver Schmidt
2012-01-12 12:38           ` Oliver Schmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).