Fixes to key codes in keyboard events generated by wxMSW.

Only set Unicode key code if the event corresponds to a character key and set
it to (newly added) WXK_NONE for the other ones to avoid nonsensical values in
it for e.g. "Home" key presses.

Also set non-Unicode key to WXK_NONE for the characters that can't be
represented in the current locale. This is consistent with wxGTK and avoids
conflicts between special key values and Unicode keys.

Clearly document the above behaviour.

Notice that implementing the correct behaviour in wxMSW involved untangling
previously interwoven WM_KEY{DOWN,UP} and WM_CHAR messages handlers. Clearly
separate them now as they get different input (key codes for the former,
characters for the latter) and especially don't try to convert from both kinds
of input using a single wxCharCodeMSWToWX() function. As this function doesn't
need to distinguish between keys and characters any more it can simply return
the converted value in all cases instead of returning 0 sometimes to indicate
a character value instead of a key. Simplify the code using this function
accordingly.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65522 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-09-11 10:18:47 +00:00
parent 86408a0374
commit b6885972ee
8 changed files with 184 additions and 110 deletions

View File

@@ -348,9 +348,9 @@ wxString GetKeyName(const wxKeyEvent &event)
const char* virt = GetVirtualKeyCodeName(keycode);
if ( virt )
return virt;
if ( keycode > 0 && keycode < 27 )
if ( keycode > 0 && keycode < 32 )
return wxString::Format("Ctrl-%c", (unsigned char)('A' + keycode - 1));
if ( keycode >= 27 && keycode < 128 )
if ( keycode >= 32 && keycode < 128 )
return wxString::Format("'%c'", (unsigned char)keycode);
#if wxUSE_UNICODE
return wxString::Format("'%c'", event.GetUnicodeKey());
@@ -371,7 +371,7 @@ void MyFrame::LogEvent(const wxString& name, wxKeyEvent& event)
" none "
#endif
#ifdef wxHAS_RAW_KEY_CODES
" %7lu 0x%lx"
" %7lu 0x%08lx"
#else
" not-set not-set"
#endif