waldrumpus
waldrumpus

Reputation: 2590

Polling the keyboard in Cocoa

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

Answers (2)

NSResponder
NSResponder

Reputation: 16861

Don't poll the keyboard, just implement -keydown: in your App delegate class.

Upvotes: 0

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:

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

Related Questions