Which Control key has been pressed (left or right)?

I’m developing a small application where I allow the user to map the keys. The problem is that there are two Ctrl and Shift keys, and other keys like “fn”, or language specific keys. ModifierKeysChanged() doesn’t provide enough information about which key has been used.

Is there any way to obtain which real key has been pressed or released and being able to identify it?

I’ve digging into JUCE code and I see that it has a MSG object which has a lParam variable with a code which seems unique for each key. Should I hack it? Or is it the wrong parameter?

        static LRESULT CALLBACK keyboardHookCallback (int nCode, WPARAM wParam, LPARAM lParam)
        MSG& msg = *(MSG*) lParam;

       // More code here...

JUCE doesn’t provide the distinction between LCTRL and RCTRL (same for shift and option/alt). This would definitely be useful for video games…

In any case, for straight up Windows - this is how you do it: https://stackoverflow.com/a/5681468/1907103

For macOS, there’s no obvious solution. This comes up as one: https://stackoverflow.com/a/10716369/1907103

Linux can also tell the difference (grep for updateKeyModifiersFromSym in JUCE), and I’m imagining Android outta be able to.

Thanks for the reply. I’m not skilled at all with windows / osx api, so this is very cryptic for me.

I’ve been reading about it, and since JUCE does a hook already, my only option is using GetKeyState(VK_RCONTROL) in the KeyListener’s functions, since GetAsyncKeystate(VK_RCONTROL) may interfere JUCE’s hook.

GetKeyState works in Windows, but I don’t know if there is any danger using it.

TBH, this reported issue sounds to me like a valid feature request - one that every framework should have… I suggest making a new post to represent that.

1 Like

I did. Thanks!

I think there’s no way of detecting the Windows key being down either, if there’s someone doing some work on this!?

VK_LWIN and VK_RWIN are what you want (to request)! (add VK_APPS to the list for the Menu/FN key)

Indeed, VK_LCONTROL, VK_RCONTROL, and Shift/Alt equivalents. With direct access, I mean that bool keyStateChanged(bool isKeyDown) should have an equivalent bool keyStateChanged(bool isKeyDown, int keyCode).