Get all interactions from external keyboard

Saltemohn 101 Reputation points
2021-03-25T11:26:13.037+00:00

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

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,297 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,309 questions
{count} votes

Accepted answer
  1. Saltemohn 101 Reputation points
    2021-03-25T17:47:38.42+00:00

    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);
            }
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful