Remove a hack for keyboard group switching.
Always save/restore correct keyboard group index.
Explicitly ignore the keyboard group switching events.

diff --git a/include/winuser.h b/include/winuser.h
index d1daa24..241f44c 100644
--- a/include/winuser.h
+++ b/include/winuser.h
@@ -2109,7 +2109,6 @@
   /* keybd_event flags */
 #define KEYEVENTF_EXTENDEDKEY        0x0001
 #define KEYEVENTF_KEYUP              0x0002
-#define KEYEVENTF_WINE_FORCEEXTENDED 0x8000
 
   /* mouse_event flags */
 #define MOUSEEVENTF_MOVE        0x0001
diff --git a/windows/input.c b/windows/input.c
index 7d69b5c..408d214 100644
--- a/windows/input.c
+++ b/windows/input.c
@@ -123,9 +123,8 @@
 
     if (ki->dwFlags & KEYEVENTF_KEYUP )
     {
-        BOOL sysKey = ((InputKeyStateTable[VK_MENU] & 0x80) &&
-                       !(InputKeyStateTable[VK_CONTROL] & 0x80) &&
-                       !(ki->dwFlags & KEYEVENTF_WINE_FORCEEXTENDED)); /* for Alt from AltGr */
+        BOOL sysKey = (InputKeyStateTable[VK_MENU] & 0x80) &&
+                      !(InputKeyStateTable[VK_CONTROL] & 0x80);
         InputKeyStateTable[ki->wVk] &= ~0x80;
         keylp.lp1.previous = 1;
         keylp.lp1.transition = 1;
diff --git a/windows/x11drv/keyboard.c b/windows/x11drv/keyboard.c
index aca6e60..1f26228 100644
--- a/windows/x11drv/keyboard.c
+++ b/windows/x11drv/keyboard.c
@@ -618,7 +618,7 @@
     return keyc2vkey[e->keycode];
 }
 
-static BOOL NumState=FALSE, CapsState=FALSE, AltGrState=FALSE;
+static BOOL NumState=FALSE, CapsState=FALSE;
 
 /**********************************************************************
  *		KEYBOARD_GenerateMsg
@@ -735,7 +735,6 @@
     KeySym keysym;
     WORD vkey = 0, bScan;
     DWORD dwFlags;
-    static BOOL force_extended = FALSE; /* hack for AltGr translation */
     int ascii_chars;
 
     DWORD event_time = event->time - X11DRV_server_startticks;
@@ -746,6 +745,13 @@
 
     ascii_chars = TSXLookupString(event, Str, sizeof(Str), &keysym, NULL);
 
+    /* Ignore some unwanted events */
+    if (keysym == XK_ISO_Prev_Group || keysym == XK_ISO_Next_Group)
+    {
+	TRACE("Ignoring %s keyboard event\n", TSXKeysymToString(keysym));
+	return;
+    }
+
     TRACE_(key)("state = %X\n", event->state);
 
     /* If XKB extensions is used, the state mask for AltGr will used the group
@@ -757,27 +763,7 @@
        predefined group index and find it dynamically
 
        Ref: X Keyboard Extension: Library specification (section 14.1.1 and 17.1.1) */
-    if ( AltGrState && (event->state & 0x6000) )
-        AltGrMask = event->state & 0x6000;
-
-    if (keysym == XK_Mode_switch)
-	{
-	TRACE_(key)("Alt Gr key event received\n");
-	event->keycode = kcControl; /* Simulate Control */
-	X11DRV_KEYBOARD_HandleEvent( event, x, y );
-
-	event->keycode = kcAlt; /* Simulate Alt */
-	force_extended = TRUE;
-	X11DRV_KEYBOARD_HandleEvent( event, x, y );
-	force_extended = FALSE;
-    
-    /* Here we save the pressed/released state of the AltGr key, to be able to 
-       identify the group index associated with AltGr on the next key pressed *
-       see comment above. */
-    AltGrState = (event->type == KeyPress) ? TRUE : FALSE;
-    
-	return;
-	}
+    AltGrMask = event->state & 0x6000;
 
     Str[ascii_chars] = '\0';
     if (TRACE_ON(key)){
@@ -792,7 +778,6 @@
     }
 
     vkey = EVENT_event_to_vkey(event);
-    if (force_extended) vkey |= 0x100;
 
     TRACE_(key)("keycode 0x%x converted to vkey 0x%x\n",
                 event->keycode, vkey);
@@ -834,7 +819,6 @@
 	dwFlags = 0;
 	if ( event->type == KeyRelease ) dwFlags |= KEYEVENTF_KEYUP;
 	if ( vkey & 0x100 )              dwFlags |= KEYEVENTF_EXTENDEDKEY;
-	if ( force_extended )            dwFlags |= KEYEVENTF_WINE_FORCEEXTENDED;
 
         KEYBOARD_SendEvent( vkey & 0xff, bScan, dwFlags, x, y, event_time );
     }
@@ -1527,14 +1511,13 @@
     if (lpKeyState[VK_CAPITAL] & 0x01)
 	e.state |= LockMask;
     if (lpKeyState[VK_CONTROL] & 0x80)
-    {
-	if (lpKeyState[VK_MENU] & 0x80)
-	    e.state |= AltGrMask;
-	else
-	    e.state |= ControlMask;
-    }
+	e.state |= ControlMask;
     if (lpKeyState[VK_NUMLOCK] & 0x01)
 	e.state |= NumLockMask;
+
+    /* Restore saved AltGr state */
+    e.state |= AltGrMask;
+
     TRACE_(key)("(%04X, %04X) : faked state = %X\n",
 		virtKey, scanCode, e.state);
     /* We exit on the first keycode found, to speed up the thing. */