Now that we have iOS 7, Apple apparently has removed the option to receive keyboard notifications from -sendEvent:
. This is a huge pain to people who are wanting to write something that captures all key events and sends it off to a remote computer, E.G. a VNC client. UIKeyCommand
does not provide the functionality needed. There are many bug reports submitted to apple, but they will not listen. The bug report apple is closing all reports as a duplicate is rdar://14129420.
What is the best solution for this?
I have at least been able to get these events back the private API way, however the keyup doesn't return any useful info such as the key that was released. Maybe this is something which can be pulled from
UIEvent
?The code that's needed to be added is the following definition of
UIPhysicalKeyboardEvent
.To listen for events, use the following in a
UIResponder
. I am not sure if the responder needs to be key or not.I'm hoping that this code will at least be of some help to people who needs this. You can determine when the command key, option key, and control key is pressed using
_modifierFlags
. I haven't played around with it much, but seems to be an good way to get the events.You could possibly borrow code from http://nacho4d-nacho4d.blogspot.com/2012/01/catching-keyboard-events-in-ios.html to improve. If anyone else finds a better way, please post them!
Since this is using private APIs, it might be better for you to wrap everything in
respondsToSelector
. Things such as_unmodifiedInput
.I am not sure if apple would accept an application that implements this, so use at your own risk.
Override this method on UIApplication and have fun :)