(Modifier-)Keystate without any component having focus

Hello,

I only get the keystate of modifierkeys in mouseMove if at least one component has the focus (Component::getCurrentlyFocusedComponent() != nullptr). But there is no focus, if the plugin-window was actived by clicking the window-titelbar or activating the host-window. Is there a way to get the global keystate of modifier-keys regardless of any component having the focus?

I want to move the slider-thumb automatically to the mouseposition (without clicking it) while a modifier-key (fe shift) is pressed. This works fine, if the user has clicked inside the plugin-window befor but doesn’t, if just the window itself has the focus.

I probably could implement my own windowshook but would prefer a build-in solution, if available.

I neet this feature for VST3 on Windows and Mac.

There is a static method in ModifierKeys:
ModifierKeys::getCurrentModifiers()

Does that work? As I understand the docs, it should be available at any time

unfortunately, not. The flags a zero until the plugin-window was clicked inside.

You need ComponentPeer::getCurrentModifiersRealtime(), but it does not work in all hosts.

1 Like

Thank you. That works. Do you maybe know hosts who doesn’t support this feature? Is it more a host or a platform-thing? I tried to dig via single-step into the code. but to be honest, I didn’t understand anything whats going on there.

I know Pro Tools on Windows partially blocks this because it has its own modifiers handling scheme. Any other host might theoretically do the same thing. If a host decides to add a system-wide keyboard hook, then the underlying windows call GetAsyncKeyState() might only provide filtered results.

On OSX things appear to be perfectly fine with the call.

1 Like

Would a hook via WH_GETMESSAGE (like its implemented in WindowsHooks-class) suffer from the same problem?

no sure. There are also the low-level keyboard and mouse hooks in windows. It probably depends on the order in which the hooks are added. However if you are using JUCE you shouldn’t have to use any windows hooks in your code and in this case it seems like an overkill and in general getCurrentModifiersRealtime() works just fine.

1 Like

this question was more for my own understanding/interest (or if things change in future). getCurrentModifiersRealtime is what I was looking for and works in my current scenario. so, thanks for that.