Reputation: 2590
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?
Upvotes: 0
Views: 622
Reputation: 16861
Don't poll the keyboard, just implement -keydown:
in your App delegate class.
Upvotes: 0
Reputation: 5558
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
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).
Upvotes: 3