How to known lower/upper case letter in EVT_CHAR_HOOK handler Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Ronald
I live to help wx-kind
I live to help wx-kind
Posts: 162
Joined: Mon Mar 05, 2018 4:17 am

How to known lower/upper case letter in EVT_CHAR_HOOK handler

Post by Ronald » Sat Dec 07, 2019 4:02 pm

In the code below, if press shift+A, it outputs 306(code of shift) and 'A' seperately.
What's wanted is key codes like 'a', 'A', '1', '!', etc, any easy way?

Code: Select all

void MainFrame::OnCharHook(wxKeyEvent & event)
{
    wxChar uc = event.GetUnicodeKey();
    if (uc != WXK_NONE)
    {
        // It's a "normal" character. Notice that this includes
        // control characters in 1..31 range, e.g. WXK_RETURN or
        // WXK_BACK, so check for them explicitly.
        if (uc >= 0x20)
        {
            Logger::Log("You pressed '%c'", uc);
        }
        else
        {
            // It's a control character
        }
    }
    else // No Unicode equivalent.
    {
        // It's a special key, deal with all the known ones:
        int kc = event.GetKeyCode();
        Logger::Log("You pressed %d", kc);
    }

    event.Skip();
}

User avatar
doublemax
Moderator
Moderator
Posts: 15277
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to known lower/upper case letter in EVT_CHAR_HOOK handler

Post by doublemax » Sat Dec 07, 2019 4:21 pm

I think only wxEVT_CHAR will give you the translated key code.
Use the source, Luke!

Post Reply