0
votes

I have a feeling I know the answer to this question, but it's been surprisingly difficult to confirm it anywhere. Is it possible to get raw keyboard and mouse input post-Catalina without needing "Input Monitoring" access in the Security & Privacy preferences?

Security & Privacy prompt

I've never programmed a game engine before on macOS, but so far as I can tell, the "usual" way for games to get raw mouse deltas and raw keyboard states has been to use IOKit's HID API. Up until recently, this apparently was also the only way to get input from Xbox and Playstation gamepads.

When I attempt to use the IOKit HID API to get mouse and keyboard input, I receive a prompt to allow Input Monitoring in Security & Privacy preferences. Elsewhere on the internet, I've learned that this is due to a change in macOS Catalina: to use IOKit HID input handling, you now need the Input Monitoring permission. As far as I'm concerned, it's a deal-breaker for my game to require users turn this on.

Am I understanding this situation correctly? And if I am, is it just not possible to get raw (unprocessed) keyboard and mouse input without the Input Monitoring permission? I mean, I can hack together a solution for FPS-style mouse input using mouseMoved: events and the like, but such a solution would disallow sub-pixel precision and would subject my game to macOS's cursor acceleration. Is there another solution that games/game engines use?

1
I've decided to move on with regular Cocoa keyboard events, though this leaves me without a way to detect a few things (like the release of the Caps Lock key). I still have a little trouble believing that Apple wouldn't have a "preferred" way to get raw mouse deltas suitable for 3D computer games.theOtherMichael

1 Answers

1
votes

If you’re willing to take on the macOS 11 requirement, it seems like Apple added raw keyboard and mouse support to the Game Controller framework. Seems to even support caps lock.

https://developer.apple.com/documentation/gamecontroller/gckeyboardinput?language=objc