question

Saltemohn-8469 avatar image
0 Votes"
Saltemohn-8469 asked Saltemohn-8469 answered

Get all interactions from external keyboard

Hello everybody,
I'm searching for an event in Xamarin.iOS with C# like Androids KeyEvent (https://developer.android.com/reference/android/view/KeyEvent). It should give me the key which is involved (or an id or smoething which can be translated in the pressed key) and if the key got pressed or released. Also it should work with keys like Ctrl.

In addition, this should only work when I've selected a specific text field in my app, and, if possible, only with external keyboards.

I hope you can give me a solution :)

Best regards,
Saltemohn

dotnet-csharpdotnet-iosdotnet-xamarinessentials
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, Saltemohn-8469. Try using UIApplication.sendEvent(_:) to dispatches an event to the appropriate responder objects. Here is the similar issue case, you could refer to it.

https://stackoverflow.com/questions/19928361/iosconvert-objc-code-to-c-how-to-know-the-time-app-has-been-idle/19931740#19931740

0 Votes 0 ·

Thank you very much for your answer. Unfortunately, it doesn't help me. With that event I can only tell if someone touched the screen, not, which key is pressed. In addition, it doesn't work with external (bluetooth) keyboards.

0 Votes 0 ·

1 Answer

Saltemohn-8469 avatar image
1 Vote"
Saltemohn-8469 answered

I finally found a solution by myself. If another person with the same problem finds hat question:

     public override void PressesBegan(NSSet<UIPress> presses, UIPressesEvent press)
         {
             var pressesArray = presses.ToArray<UIPress>();
             var key = pressesArray.First()?.Key;
             if(key == null)
                 return;
    
             Console.WriteLine(key.KeyCode);
    
             base.PressesBegan(presses, press);
         }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.