Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How can I Intercept Hardware Keyboard buttons?

Hi everyone,
I'm trying to have access to the hardware keyboard of the flip-phone: LG Wine Smart (http://gadgets.ndtv.com/lg-wine-smart-2015-2843).

This is what did:

`public override bool OnKeyDown(Keycode keyCode, KeyEvent e)
    {
        if (e.KeyCode == Keycode.Dvr)
        {
            //Works
            StartActivity(typeof(sms));
        }
        if (e.KeyCode == Keycode.Numpad0)
        {
            StartActivity(typeof(TakeNumbersFromMain));
        }
        if (e.KeyCode == Keycode.Num0)
        {
            StartActivity(typeof(registro));
        }
        if (e.KeyCode == Keycode.Call)
        {
            //Works 
            StartActivity(typeof(registro));
        }
        if (e.KeyCode == Keycode.Camera)
        {
            StartActivity(typeof(MainActivity));
        }
        if (e.KeyCode == Keycode.Button3)
        {
            StartActivity(typeof(TakeNumbersFromMain));
        }
        if (e.KeyCode == Keycode.Numpad3 && e.Modifiers == MetaKeyStates.ShiftOn)
        {
            CrossTextToSpeech.Current.Speak("Pound");
        }


        return base.OnKeyDown(keyCode, e);
    }`

I'm able to intercept only the "Keycode.Dvr" and the "Keycode.Call" Keys, but I also need to intercept the number keys (which in java can be called as KEYCODE 1, KEYCODE 2, KEYCODE POUND, etc.).
When I press the number keys they redirect me to the default dialer, but my goal is to intercept them and use them in another activity.
How can I do that?

Thank you!

p.s. Sorry for the strange format of the code

Sign In or Register to comment.