]> git.saurik.com Git - wxWidgets.git/commitdiff
Generate correct events for extended keys in wxMSW wxUIActionSimulator.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 11 Sep 2010 10:18:25 +0000 (10:18 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 11 Sep 2010 10:18:25 +0000 (10:18 +0000)
Simulating keys such as WXK_END resulted in WXK_NUMPAD_END event being
generated instead of the expected WXK_END one.

Fix this by returning from wxCharCodeWXToMSW() whether the key code is a
normal or extended one and use this to set KEYEVENTF_EXTENDEDKEY in
wxUIActionSimulator::DoKey().

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65518 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/window.h
src/msw/uiaction.cpp
src/msw/window.cpp

index d2f9d1be90e927ab7cd6d9c093663fbd966d4675..a41c1e4fed8429fd1856626ca52eab93213337cf 100644 (file)
@@ -644,9 +644,9 @@ private:
 // global functions
 // ---------------------------------------------------------------------------
 
-// kbd code translation
+// key codes translation between wx and MSW
 WXDLLIMPEXP_CORE int wxCharCodeMSWToWX(int keySym, WXLPARAM lParam = 0);
-WXDLLIMPEXP_CORE WXWORD wxCharCodeWXToMSW(int id);
+WXDLLIMPEXP_CORE WXWORD wxCharCodeWXToMSW(int id, bool *isExtended = NULL);
 
 // window creation helper class: before creating a new HWND, instantiate an
 // object of this class on stack - this allows to process the messages sent to
index d8f498cbd8165137c86dccea285d42e027d1ca59..ee59fd0603174501a5f6f440f2716a93c27d7bc2 100644 (file)
@@ -74,8 +74,16 @@ bool wxUIActionSimulator::MouseUp(int button)
 bool
 wxUIActionSimulator::DoKey(int keycode, int WXUNUSED(modifiers), bool isDown)
 {
-    DWORD vkkeycode = wxCharCodeWXToMSW(keycode);
-    keybd_event(vkkeycode, 0, isDown ? 0 : KEYEVENTF_KEYUP, 0);
+    bool isExtended;
+    DWORD vkkeycode = wxCharCodeWXToMSW(keycode, &isExtended);
+
+    DWORD flags = 0;
+    if ( isExtended )
+        flags |= KEYEVENTF_EXTENDEDKEY;
+    if ( !isDown )
+        flags |= KEYEVENTF_KEYUP;
+
+    keybd_event(vkkeycode, 0, flags, 0);
 
     return true;
 }
index 623e66b16d64b6c423eb48458015b919e0554765..64bb9dca0c199fb7ee5722f05bab237048dbc9e2 100644 (file)
@@ -6199,65 +6199,84 @@ int wxCharCodeMSWToWX(int vk, WXLPARAM lParam)
     return wxk;
 }
 
-WXWORD wxCharCodeWXToMSW(int wxk)
+WXWORD wxCharCodeWXToMSW(int wxk, bool *isExtended)
 {
     // check the table first
     for ( size_t n = 0; n < WXSIZEOF(gs_specialKeys); n++ )
     {
         if ( gs_specialKeys[n].wxk == wxk )
+        {
+            // All extended keys (i.e. non-numpad versions of the keys that
+            // exist both in the numpad and outside of it) are dealt with
+            // below.
+            if ( isExtended )
+                *isExtended = false;
+
             return gs_specialKeys[n].vk;
+        }
     }
 
     // and then check for special keys not included in the table
+    bool extended = false;
     WXWORD vk;
     switch ( wxk )
     {
         case WXK_PAGEUP:
+            extended = true;
         case WXK_NUMPAD_PAGEUP:
             vk = VK_PRIOR;
             break;
 
         case WXK_PAGEDOWN:
+            extended = true;
         case WXK_NUMPAD_PAGEDOWN:
             vk = VK_NEXT;
             break;
 
         case WXK_END:
+            extended = true;
         case WXK_NUMPAD_END:
             vk = VK_END;
             break;
 
         case WXK_HOME:
+            extended = true;
         case WXK_NUMPAD_HOME:
             vk = VK_HOME;
             break;
 
         case WXK_LEFT:
+            extended = true;
         case WXK_NUMPAD_LEFT:
             vk = VK_LEFT;
             break;
 
         case WXK_UP:
+            extended = true;
         case WXK_NUMPAD_UP:
             vk = VK_UP;
             break;
 
         case WXK_RIGHT:
+            extended = true;
         case WXK_NUMPAD_RIGHT:
             vk = VK_RIGHT;
             break;
 
         case WXK_DOWN:
+            extended = true;
         case WXK_NUMPAD_DOWN:
             vk = VK_DOWN;
             break;
 
         case WXK_INSERT:
+            extended = true;
         case WXK_NUMPAD_INSERT:
             vk = VK_INSERT;
             break;
 
         case WXK_DELETE:
+            extended = true;
         case WXK_NUMPAD_DELETE:
             vk = VK_DELETE;
             break;
@@ -6279,6 +6298,9 @@ WXWORD wxCharCodeWXToMSW(int wxk)
             }
     }
 
+    if ( isExtended )
+        *isExtended = extended;
+
     return vk;
 }