Forum Xamarin.Forms

find key presses from layout controls (not entry field) in xamarin.forms

James.KirkJames.Kirk GBMember ✭✭


I need to find what key the user pressed on a keyboard using xamarin.forms, ideally inside an AbsoluteLayout. I've come up with a few ways myself, but can't get any of them working.

As there isn't an event for this on the AbsoluteLayout control, i tried a little cheat, which was putting an entry field (textbox) on the screen, but hiding it above, so it can't be seen and using the result form that, but it loses focus when someone presses the screen or a button on the screen. so i tried adding an event to each button which refocuses the textbox once i've handled the press and this seemed ok at first, however, if they press anywhere else on the screen, it also loses focus.

I also tried adding a TapGestureRecognizer to the screen, and focusing the button when they press anywhere on the screen, however, there were 2 issues with this, the first being that it appears to only fire when something inside it is touched, and secondly, when i call the focus method for the second time (if they click the screen twice) it un-focuses the entry field, even if i check "isfocused" first (think this is a bug).

I'm only concerned about windows 8 and android apps so far. iOS may come later, but for now im just trying to get it working for these OS's. so maybe i could code it in the windows and android projects (inside my shared project solution), however, i have absolutely no idea where to even begin doing that. I mean, if this is the best way, how can i pass my AbsoluteLayout to the windows project and get it to know what it is, and convert it into a control which i can then add the event to.

Any help or advice, or ideas would be much appreciated. I cant find anything in NuGet which will help me with this. Any ideas?

Many thanks


  • LuisDuenasLuisDuenas USMember ✭✭

    i have the same issue, you got any solution?

  • James.KirkJames.Kirk GBMember ✭✭

    I ended up having to code in the key events for each individual operating system. i.e. i went to the android app, found the android key events and made a keypress raise an event and tell the main class. Something like this, anyway, the gist is, you need to code it in per OS.

  • E75E75 NLMember ✭✭

    @james.kirk any updates with code examples?

Sign In or Register to comment.