Keyboard related question on MSW

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
Rohit Agarwal
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed May 19, 2021 11:17 pm
Contact:

Keyboard related question on MSW

Post by Rohit Agarwal » Mon Sep 13, 2021 3:05 am

I'm designing an app that takes a lot of keyboard input.
It needs to use the keys in the space bar row which,
except for space-bar are non-standard across platforms.
In addition to GetKeyCode, it uses GetRawKeyCode, GetRawKeyFlags and wxKeyboardState::GetModifiers
However, on MSW, I still can't differentiate between Ctrl on the left side of the keyboard
and Alt on the right side of the keyboard.
They have identical numbers for all 4 of these parameters.
I verified this using the Keyboard sample.

At the moment, I'm intercepting both KEY_DOWN and CHAR_HOOK events and sending them to the same method.

Is there a simple way to differentiate between these 2 keys on MSW --
the left control key and the right alt key.
This problem does not exist on OSX or on GTK3

OSX 11.1
Windows 10 MinGW64
Ubuntu 20.3 GTK 3
3.1.5
Last edited by Rohit Agarwal on Mon Sep 13, 2021 5:24 am, edited 1 time in total.

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

Re: Keyboard related question on MSW

Post by doublemax » Mon Sep 13, 2021 5:17 am

Under Windows, bit 24 of the GetRawKeyFlags() should be 1 for the right-hand keys (= extended key in Windows terminology).
https://docs.microsoft.com/en-us/window ... wm-keydown
(I can see that in the keyboard sample)

Be aware that the right Alt key is actually AltGr, which is not the same. It will behave the same as pressing Alt + Control together.
Use the source, Luke!

Rohit Agarwal
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed May 19, 2021 11:17 pm
Contact:

Re: Keyboard related question on MSW

Post by Rohit Agarwal » Mon Sep 13, 2021 5:28 am

Yes it is AltGr that is creating a shadow of Ctrl.
In the keyboard sample,
While Ctrl sends one set of 3 messages
Hook Ctrl
KeyDown Ctrl
KeyUp Ctrl

AltGr sends.
Hook Ctrl
KeyDown Ctrl
Hook Alt
KeyDown Alt
KeyUp Ctrl
KeyUp Alt
I guess mimicking the behaviour of pressing (Ctrl and then Alt) keys together
But the Hook and Keydown for both are identical (corresponding to Ctrl).
They can be differentiated on the KeyUp via the state of the modifiers but not before that.

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

Re: Keyboard related question on MSW

Post by doublemax » Mon Sep 13, 2021 6:04 am

But the bit 24 for detecting left and right Ctrl works?

As for the AltGr, i can't think of any way to distinguish that from pressing the individual keys.
Use the source, Luke!

Rohit Agarwal
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed May 19, 2021 11:17 pm
Contact:

Re: Keyboard related question on MSW

Post by Rohit Agarwal » Mon Sep 13, 2021 6:33 am

No it doesn't in this case.
All 4 parameters for the (fake) Ctrl that is generated are identical to the real Ctrl.
In general, those parameters do work (e.g. for detecting left vs. right ctrl)
doublemax wrote:
Mon Sep 13, 2021 6:04 am
But the bit 24 for detecting left and right Ctrl works?

As for the AltGr, i can't think of any way to distinguish that from pressing the individual keys.
The only way I can think of now is to track keyup.
The modifier keys on keyup are different between Left Ctrl and AltGr so that would be a cue.

Post Reply