From 9a1b36af5aa0667909a3f29e1444825a7f558292 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 31 Aug 2012 12:31:44 +0000 Subject: [PATCH] Fix example of using GetUnicodeKey() in the documentation. A Unicode key is not always printable, it can be a control character as well. Closes #14622. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72420 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- interface/wx/event.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/interface/wx/event.h b/interface/wx/event.h index d02d5a0d37..9f75e9a785 100644 --- a/interface/wx/event.h +++ b/interface/wx/event.h @@ -1406,12 +1406,23 @@ public: @code void MyHandler::OnChar(wxKeyEvent& event) { - if ( event.GetUnicodeKey() != WXK_NONE ) + wxChar uc = event.GetUnicodeKey(); + if ( uc != WXK_NONE ) { - // It's a printable character - wxLogMessage("You pressed '%c'", event.GetUnicodeKey()); + // It's a "normal" character. Notice that this includes + // control characters in 1..31 range, e.g. WXK_RETURN or + // WXK_BACK. + if ( wxIsprint(uc) ) + { + wxLogMessage("You pressed '%c'", uc); + } + else + { + // It's a control character + ... + } } - else + else // No Unicode equivalent. { // It's a special key, deal with all the known ones: switch ( GetKeyCode() ) -- 2.45.2