Generate correct events for extended keys in wxMSW wxUIActionSimulator.

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
This commit is contained in:
Vadim Zeitlin
2010-09-11 10:18:25 +00:00
parent 9cbe96d093
commit 2dcbc4615b
3 changed files with 35 additions and 5 deletions

View File

@@ -644,9 +644,9 @@ private:
// global functions // global functions
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// kbd code translation // key codes translation between wx and MSW
WXDLLIMPEXP_CORE int wxCharCodeMSWToWX(int keySym, WXLPARAM lParam = 0); 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 // 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 // object of this class on stack - this allows to process the messages sent to

View File

@@ -74,8 +74,16 @@ bool wxUIActionSimulator::MouseUp(int button)
bool bool
wxUIActionSimulator::DoKey(int keycode, int WXUNUSED(modifiers), bool isDown) wxUIActionSimulator::DoKey(int keycode, int WXUNUSED(modifiers), bool isDown)
{ {
DWORD vkkeycode = wxCharCodeWXToMSW(keycode); bool isExtended;
keybd_event(vkkeycode, 0, isDown ? 0 : KEYEVENTF_KEYUP, 0); 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; return true;
} }

View File

@@ -6199,65 +6199,84 @@ int wxCharCodeMSWToWX(int vk, WXLPARAM lParam)
return wxk; return wxk;
} }
WXWORD wxCharCodeWXToMSW(int wxk) WXWORD wxCharCodeWXToMSW(int wxk, bool *isExtended)
{ {
// check the table first // check the table first
for ( size_t n = 0; n < WXSIZEOF(gs_specialKeys); n++ ) for ( size_t n = 0; n < WXSIZEOF(gs_specialKeys); n++ )
{ {
if ( gs_specialKeys[n].wxk == wxk ) 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; return gs_specialKeys[n].vk;
}
} }
// and then check for special keys not included in the table // and then check for special keys not included in the table
bool extended = false;
WXWORD vk; WXWORD vk;
switch ( wxk ) switch ( wxk )
{ {
case WXK_PAGEUP: case WXK_PAGEUP:
extended = true;
case WXK_NUMPAD_PAGEUP: case WXK_NUMPAD_PAGEUP:
vk = VK_PRIOR; vk = VK_PRIOR;
break; break;
case WXK_PAGEDOWN: case WXK_PAGEDOWN:
extended = true;
case WXK_NUMPAD_PAGEDOWN: case WXK_NUMPAD_PAGEDOWN:
vk = VK_NEXT; vk = VK_NEXT;
break; break;
case WXK_END: case WXK_END:
extended = true;
case WXK_NUMPAD_END: case WXK_NUMPAD_END:
vk = VK_END; vk = VK_END;
break; break;
case WXK_HOME: case WXK_HOME:
extended = true;
case WXK_NUMPAD_HOME: case WXK_NUMPAD_HOME:
vk = VK_HOME; vk = VK_HOME;
break; break;
case WXK_LEFT: case WXK_LEFT:
extended = true;
case WXK_NUMPAD_LEFT: case WXK_NUMPAD_LEFT:
vk = VK_LEFT; vk = VK_LEFT;
break; break;
case WXK_UP: case WXK_UP:
extended = true;
case WXK_NUMPAD_UP: case WXK_NUMPAD_UP:
vk = VK_UP; vk = VK_UP;
break; break;
case WXK_RIGHT: case WXK_RIGHT:
extended = true;
case WXK_NUMPAD_RIGHT: case WXK_NUMPAD_RIGHT:
vk = VK_RIGHT; vk = VK_RIGHT;
break; break;
case WXK_DOWN: case WXK_DOWN:
extended = true;
case WXK_NUMPAD_DOWN: case WXK_NUMPAD_DOWN:
vk = VK_DOWN; vk = VK_DOWN;
break; break;
case WXK_INSERT: case WXK_INSERT:
extended = true;
case WXK_NUMPAD_INSERT: case WXK_NUMPAD_INSERT:
vk = VK_INSERT; vk = VK_INSERT;
break; break;
case WXK_DELETE: case WXK_DELETE:
extended = true;
case WXK_NUMPAD_DELETE: case WXK_NUMPAD_DELETE:
vk = VK_DELETE; vk = VK_DELETE;
break; break;
@@ -6279,6 +6298,9 @@ WXWORD wxCharCodeWXToMSW(int wxk)
} }
} }
if ( isExtended )
*isExtended = extended;
return vk; return vk;
} }