A manual test shows that hotkeys messages are supposed to be received even with that flag, so basically moving the NOLEGACY check right after find_hardware_message_window looks like a simple fix and goes in the right direction.
Done in v3. I considered adding tests for hotkey/rawinput interactions, but found that we emit WM_HOTKEY and WM_INPUT messages in the opposite order from Windows, so skipped them for now.