My Cocoa application should react continuously to the state of the keys pressed by the user. To that end, I would like to poll the keyboard at fixed intervals, instead of relying on keyboard events. Is there any Cocoa API to achieve this? If not, what other options exist?
My Cocoa application should react continuously to the state of the keys pressed by
Share
Polling is never such a great idea. You shouldn’t have to do that in most cases.
There is 2 API you may be interested for:
Quartz Event Taps https://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html
IOKit HID API https://developer.apple.com/library/mac/#documentation/DeviceDrivers/Conceptual/HID/intro/intro.html#//apple_ref/doc/uid/TP40000970
Please note keyboard accesses may pose some security issues so the system may not allow you to read the keyboard state. Check the Accessibility settings (access to assistive devices).