Keyboard events iOS

Hi there, anybody an idea how to get the keyboard events in iOS, looking for the event of the main “Done” button… Also, when pressing the done, the textfield seems to close but does not trigger a close field event. Anybody please?

I am not aware of a way to ket keyboard events. However, what “Done” does is simply to remove the focus from the textfield.

It is possible to detect the focused state of the TextField with the function isFirstResponder in XojoiOSWrapper
https://github.com/Mitchboo/XojoiOSWrapper

What you do is monitor the firstresponder (focused) state of your textfield in a timer, and when it turns False, it means the keyboard Done has happened, or the user has tapped outside of the textfield, both resulting in the keyboard disappearing.

Michel Bujardet, thanks! Genius…

Hi Michel, never done this before… how does it work? “how to implement it for Dummies” would be appreciated! Sorry about this…

  • Add the Wrapper module to your project (drag it from Wrapper.xojo.project)
  • Add a multiple 100 ms timer to your page
  • In the Action event of the timer, put something like this :

Static oldresponder as boolean = isFirstResponder(TextField1.Handle) if isFirstResponder(TextField1.Handle) = False and isFirstResponder(TextField1.Handle)<>oldresponder then //Done has occurred, the textfield has lost focus // Place here what you would in a "done" event end if

Hi Michel,

Just when you thought, it couldn’t get worse…

Downloaded the wrapper.xojo.uistate, since that includes the isFirstResponder, or not? Dragged that file into my project, added timer as instructed. Error in timer:action code: isFirstResponder does not exist

If I copy and paste the wrapper.xojo.project file that you mention the second time, into the method of a module, looks even worse… not to sure what to pass on if anything has to… if I have to use that file, I really don’t know what to do with it…

Thanks so much!

  • Download the zip by clicking on the right of the page
  • When you got the zip, double click on it to extract
  • In the extracted folder, open Wrapper.xojo_project
  • The wrapper I am talking about that you must copy into your project is the module called wrapper

Oh, that simple… Great!

Now one error left… Syntax error at Constant EndOLine: Wrapper.EndOfLine…

[quote=162924:@Nic Kolbe]Oh, that simple… Great!

Now one error left… Syntax error at Constant EndOLine: Wrapper.EndOfLine…[/quote]

Just remove EndOfLIne

I figured that, but then again, isfirstresponder does not exist.

Checked the included methods, can’t find the fitting one, lots of others though… from ASC to VAL… no isFirstResponder… Sorry about this…

[quote=162945:@Nic Kolbe]I figured that, but then again, isfirstresponder does not exist.

Checked the included methods, can’t find the fitting one, lots of others though… from ASC to VAL… no isFirstResponder… Sorry about this…[/quote]

isFirstResponder is the 13th one, right after instr and just before Left …

[code]Function isFirstResponder(extends c As iOSControl) As Boolean
declare function isFirstResponder lib “Foundation.Framework” selector “isFirstResponder” (obj_id as Ptr) as boolean

Return isFirstResponder(c.handle)
End Function
[/code]

/Users/nickolbe/Desktop/SS.png

Strange but was not there… downloaded zip again, now fine. Now error in the action of my timer: This method extends class iOSControl, but the base expression is class ViewiPhone.ViewiPhone.

Also, the EOL was fine just an error about the end of line properties, which I changed from String to text… That’s fine now…

if TextField1.isFirstResponder then

You can in fact natively register for keyboard events.
This is the one you might use to detect the Done button being pressed: textFieldShouldEndEditing:

Dunno anything about Xojo iOS so someone else will have to help you with the declare.

However, since right after that notification is done being handled the text editor releases FirstResponder Michel’s workaround is probably the next best thing. You would only need to handle the event if you need to cancel it, or if bugs surface.

[quote=162973:@Tim Parnell]You can in fact natively register for keyboard events.
This is the one you might use to detect the Done button being pressed: textFieldShouldEndEditing:

Dunno anything about Xojo iOS so someone else will have to help you with the declare.

However, since right after that notification is done being handled the text editor releases FirstResponder Michel’s workaround is probably the next best thing. You would only need to handle the event if you need to cancel it, or if bugs surface.[/quote]

Access to delegates in Xojo is sketchy at best. I would not even know how to get to textFieldShouldEndEditing, and people a lot more advanced than me have often pointed out that it was simply impossible to access delegates with declares for lack of information about the inner workings of Xojo.

Thanks! It works! Had to tweak it a bit, but now it does exactly what I want! THANKS, thanks, thanks… Michel, great teacher with a difficult student… Learned a lot… Love and light… :slight_smile:

Is there a little example project where I can spy how this isFirstResponder trick is working?
I can’t make it work…