::wxGetKeyState(WXK_COMMAND) does Not work properly on Mac

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
hardik_shah
Earned a small fee
Earned a small fee
Posts: 16
Joined: Wed Apr 22, 2009 10:15 am
Location: India

::wxGetKeyState(WXK_COMMAND) does Not work properly on Mac

Post by hardik_shah »

Hi,

I am trying to figure out Down/Up state of 'Command' key on Mac and am using following statement:

::wxGetKeyState(WXK_COMMAND);

Although Command key is pressed, this returns false.

I am NOT using this in any of mouse key handler, but am using it in normal function. Is it still okay to use?

The keyboard which I am using is Standard 104 Keys Windows keyboard and Not Mac keyboard. And I am pressing Left-Windows key which is equivalent to Command key.

Should wxGetKeyState(WXK_COMMAND) work in above scenario?

wxWidgets Ver: 2.8
Mac OS X: 10.5.7
XCode: 3.0

Thanks,
Hardik
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Hi,

have you tried other keys? i.e. do all keys fail or only command?

In either case, I think this may well be worth a bug report.

hint: if what you're trying to do is get keyboard shortcuts to work, there's much easier/cleaner ways
"Keyboard not detected. Press F1 to continue"
-- Windows
hardik_shah
Earned a small fee
Earned a small fee
Posts: 16
Joined: Wed Apr 22, 2009 10:15 am
Location: India

Post by hardik_shah »

Auria wrote:Hi,

have you tried other keys? i.e. do all keys fail or only command?

In either case, I think this may well be worth a bug report.

hint: if what you're trying to do is get keyboard shortcuts to work, there's much easier/cleaner ways
Hi Auria,

Yes, I tried with other keys and they worked.

I think, I've found the solution! While debugging deep into wxWidgets library for Mac, I found that 'Command' key on Mac is tied up with WXK_MENU keycode, instead of WXK_COMMAND ?!!

See below:
../wxWidgets/src/mac/carbon/app.cpp

Code: Select all

int wxMacKeyCodeToModifier(wxKeyCode key)
{
    switch (key)
    {
    case WXK_START:
    case WXK_MENU:
        return cmdKey;

    case WXK_SHIFT:
        return shiftKey;

    case WXK_CAPITAL:
        return alphaLock;

    case WXK_ALT:
        return optionKey;

    case WXK_CONTROL:
        return controlKey;

    default:
        return 0;
    }
}
This is really strange and it is documented nowhere in wxWidgets help/documentation.

This should be corrected...

I got required functionality after calling wxGetKeyState(WXK_MENU) for 'Command' Key.

Thank you for your help and reply.

-Hardik.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

This may be worth a bug report on the trac bug tracker (if you know how to fix it, a patch would be even better)
"Keyboard not detected. Press F1 to continue"
-- Windows
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

i'm not sure if this is a bug. It's somewhat explained here, although they don't use WXK_MENU:
http://docs.wxwidgets.org/stable/wx_key ... ymodifiers
Use the source, Luke!
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

doublemax wrote:i'm not sure if this is a bug. It's somewhat explained here, although they don't use WXK_MENU:
http://docs.wxwidgets.org/stable/wx_key ... ymodifiers
Well then it's a documentation bug ;)
"Keyboard not detected. Press F1 to continue"
-- Windows
hardik_shah
Earned a small fee
Earned a small fee
Posts: 16
Joined: Wed Apr 22, 2009 10:15 am
Location: India

Post by hardik_shah »

Auria wrote:
doublemax wrote:i'm not sure if this is a bug. It's somewhat explained here, although they don't use WXK_MENU:
http://docs.wxwidgets.org/stable/wx_key ... ymodifiers
Well then it's a documentation bug ;)
Well, I feel it's implementation bug as well.

Since there is already a define WXK_COMMAND in the library, it should be mapped for Command Key rather than any other keys.

I will be glad to fix this in wxWidgets library, if I am allowed to do this. If you agree that, this qualify for a fix, please guide me where to log a bug and find the library code.

Thanks,
Hardik
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

See http://trac.wxwidgets.org/ for bug reports and patch submission
As for where to find the wxWidgets code, a quick google or lurking around wxwidgets.org will sure tell you quickly enough ;)
"Keyboard not detected. Press F1 to continue"
-- Windows
Post Reply