Skip to content

Conversation

@estroBiologist
Copy link

This PR implements keyboard event hooking on Windows, a technique also used by JUCE to get around restrictions on keyboard input imposed by various hosts. By intercepting Win32 messages using SetWindowsHookEx, we can bypass the host and forward keyboard messages to the baseview window directly.

This resolves the longstanding issue with keyboard input in Ableton, and likely renders many existing hacks for this problem obsolete (though I haven't tested that part yet.)

The meat of the implementation is in the new src/win/hook.rs module, which registers a simple event hook that intercepts keyboard-related WM_ events addressed to baseview windows, and forwards them into the relevant window's event handler directly, consuming the message in the process.

Couple notes:

  • There's some pretty nasty code for detecting baseview windows and forwarding events to them in hook.rs. If anyone has any better ideas for how to achieve this, I'm all ears, but it does seem to work as is.
  • I had to add the dtor crate to the windows dependencies to properly detach the hook on DLL exit. Hope that's okay!
  • I tried to keep the code reasonably clean, but neither my Win32 nor my Unsafe Rust skills are particularly great, so I hope it's all up to snuff.

The keyboard hook in action:
yesssss

@estroBiologist
Copy link
Author

(Just for the record: it turns out the message zeroing is in fact important (causes duplicate inputs if omitted) and we agreed in the Discord to leave it in)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants