locked
Android Devicemanager simulator with phycical keys RRS feed

  • Question

  • User388064 posted

    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

    Monday, January 25, 2021 12:18 PM

All replies

  • User369978 posted

    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.

    Tuesday, January 26, 2021 2:49 AM