Take the 2-minute tour ×

Possible Duplicate:
Detect key press on virtual keyboard

I wanted to know is it possible to capture the exact keyboard key press time and release time in an iOS application development?

For example, let's say I type "Hello". I'd like to know the H-Key pressed time and release time, then E, L etc. I think the answer will be in microseconds but that is what I want.

Any help would be really useful.

share|improve this question

marked as duplicate by futureelite7, Doorknob 冰, Kate Gregory, Ram kiran, Sankar Ganesh Feb 4 '13 at 4:55


2 Answers 2

You can use -(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string (from UITextFieldDelegate) to intercept typed characters in UITextField and record the timestamps there.

This at least gives you the release times. Press times are probably much harder, particularly when you consider keys that you have to press longer to get to accented versions of the character.

share|improve this answer
That will not get separate key down and up times though –  David Rönnqvist Feb 3 '13 at 16:08
Yes, I updated my answer. –  Gereon Feb 3 '13 at 16:11
And Idea came into my mind to build my own keyboard using UIButtons, but that seems to be much much harder. I can you UIButoon isPressed and isRelease functions. –  SyCruX Feb 3 '13 at 16:13

You will need to make your own keyboard and add events for Touch Down and Touch Up Inside on the buttons where you want to have this information.

Once you have your own keyboard, it is simply a matter of storing the NSDate when the button is pressed, and then subtracting that from the NSDate when it is released in order to get the elapsed time. The time will much more likely be in milliseconds (rather than microseconds) since the run-loop doesn't even go that fast.

I have an open-source project (MIT license) on Github which creates a custom numeric keyboard (you will have to add your own events to the buttons) available which should make implementing a keyboard trivially easy, here: https://github.com/lnafziger/Numberpad

You can add more/different buttons if you want to use letters as well (no code changes should be needed) on this keyboard.

share|improve this answer
