Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Android Devicemanager simulator with phycical keys

I want to create a android simulator which is having a special physical keyboard.Normal keyboard behavior of simulator is when we tap on a controller keyboard appear but in my case i need a physical keyboard to capture user key-press events.
By using those key press event i`m planing to navigate user to relevant page like a shortcut

the device keyboard what i tried to simulate is like below

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited January 26

    The device manager does not support to create such emulator with physical keys .

    We can only use DispatchKeyEvent method to detect the input on physical keyboard.

    public override bool DispatchKeyEvent(KeyEvent e)
            {
    
                switch (e.KeyCode)
                {
                    case Keycode.Power:
                        Toast.MakeText(this, "Power pressed", ToastLength.Long).Show();
                        return true;
                    case Keycode.VolumeUp:
                        Toast.MakeText(this, "Volume Up pressed", ToastLength.Long).Show();
                        return true;
                    case Keycode.VolumeDown:
                        Toast.MakeText(this, "Volume Up pressed", ToastLength.Long).Show();
                        return true;
                    case ....
                }
    
                return base.DispatchKeyEvent(e);
    
            }
    

    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

Sign In or Register to comment.