- event.m_rawCode = (wxUint32) gdk_event->keyval;
- event.m_rawFlags = 0;
-#if wxUSE_UNICODE
- event.m_uniChar = gdk_keyval_to_unicode(gdk_event->keyval);
- if ( !event.m_uniChar && event.m_keyCode <= WXK_DELETE )
+
+ // Normally we take the state of modifiers directly from the low level GDK
+ // event but unfortunately GDK uses a different convention from MSW for the
+ // key events corresponding to the modifier keys themselves: in it, when
+ // e.g. Shift key is pressed, GDK_SHIFT_MASK is not set while it is set
+ // when Shift is released. Under MSW the situation is exactly reversed and
+ // the modifier corresponding to the key is set when it is pressed and
+ // unset when it is released. To ensure consistent behaviour between
+ // platforms (and because it seems to make slightly more sense, although
+ // arguably both behaviours are reasonable) we follow MSW here.
+ //
+ // Final notice: we set the flags to the desired value instead of just
+ // inverting them because they are not set correctly (i.e. in the same way
+ // as for the real events generated by the user) for wxUIActionSimulator-
+ // produced events and it seems better to keep that class code the same
+ // among all platforms and fix the discrepancy here instead of adding
+ // wxGTK-specific code to wxUIActionSimulator.
+ const bool isPress = gdk_event->type == GDK_KEY_PRESS;
+ switch ( gdk_event->keyval )