wxGetKeyState always returns false

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
nmset
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Nov 26, 2010 4:48 pm

wxGetKeyState always returns false

Post by nmset » Fri Feb 26, 2021 9:27 pm

On latest revision 94812c9e06c, wxGetKeyState(WXK_CAPITAL) is always false, even with CAPS LOCK on. Same for WXK_NUMLOCK. Last known good commit is c3856766107b.

I use it to show CAPS and NUM lock state in a status bar.

Should it be reported as a bug ?

Thank you.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 3042
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxGetKeyState always returns false

Post by PB » Fri Feb 26, 2021 9:39 pm

I am not on the latest commit but I am certainly not on a commit from 2020 yet it works for me as expected

Code: Select all

#include <wx/wx.h>

class MyApp : public wxApp
{
public:
    bool OnInit() override
    {
        wxDialog    dlg(nullptr, wxID_ANY, "Test");
        wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);

        mainSizer->Add(new wxButton(&dlg, wxID_ANY, "Report Caps Lock State"), wxSizerFlags().Expand().TripleBorder());
        dlg.Bind(wxEVT_BUTTON, [](wxCommandEvent&) { wxLogMessage("Caps Lock %s, NumLock %s",
            wxGetKeyState(WXK_CAPITAL) ? "ON" : "OFF", wxGetKeyState(WXK_NUMLOCK) ? "ON" : "OFF"); });
        dlg.SetSizerAndFit(mainSizer);

        dlg.ShowModal();
        return false;
    }
}; wxIMPLEMENT_APP(MyApp);
So I it would seem that wxGetKeyState() itself is not an issue.

I am on Windows (10) but I assume so are you.

nmset
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Nov 26, 2010 4:48 pm

Re: wxGetKeyState always returns false

Post by nmset » Fri Feb 26, 2021 9:50 pm

Just tested your code, NUM and CAPS lock both report false, always, on Arch Linux with latest commit (GTK3 build).

PB
Part Of The Furniture
Part Of The Furniture
Posts: 3042
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxGetKeyState always returns false

Post by PB » Fri Feb 26, 2021 9:59 pm

When you did not report the platform I assumed the dominant one, i.e., MS Windows. Anyway, I tried with wxWidgets 3.1.4 (GTK3), which are newer than the "last good commit" you referenced, on Ubuntu 20.04 and it still works.

I found out that the statbar sample also displays the Caps and Num locks state (I had to use menu command Status Bar / Recreate there, make the frame larger yet the indicators were still ellipsized). Can you reproduce it there? If so, I would file a report on wxTrac.

nmset
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Nov 26, 2010 4:48 pm

Re: wxGetKeyState always returns false

Post by nmset » Fri Feb 26, 2021 10:10 pm

It's always OFF in the statbar sample. I'll report it tomorrow.

Thanks for your input.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 3042
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxGetKeyState always returns false

Post by PB » Fri Feb 26, 2021 10:13 pm

I would just make sure the last good commit is correct. It seems that the next commit is
https://github.com/wxWidgets/wxWidgets/ ... 700915023b
which does not change any code.

nmset
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Nov 26, 2010 4:48 pm

Re: wxGetKeyState always returns false

Post by nmset » Sat Feb 27, 2021 10:31 am

Reported on trac [url]https://trac.wxwidgets.org/ticket/19083[/url], with a significant bisection result.

Post Reply