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
// ---------------------------------------------------------------------------
// 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

View 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;
}

View 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;
}