Function Key Capture - Xamarin

Tags: 

Hi there, am new to Xamarin and need some advice.

We have migrated from a VS2008 application on a window CE 6.0 RF device (Motorola) to VS2017 & Xamarin on a Zebra MC9300. The android apk is installed and is running fine but we now need to use the function keys, i.e. F1, F2, etc.This is not coded.

Does anyone have any sample code on how to do this? Do I need EMDK? In the older application we used the form's key down event to capture. Any direction would be greatly appreciated.

Thanks for you time.'

Darryn Campbell
You should be able to use

You should be able to use Android's KeyEvents - the keycodes for the function keys are defined in Android docs https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_F1.  Note that these are different from the previous values used in WinCE http://www.kbdedit.com/manual/low_level_vk_list.html (I can't find an official list).

There are not any special APIs in EMDK for function keys

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Patrick Kennedy
Hi Darryn, thanks for your

Hi Darryn, thanks for your input. Do you have idea if there's sample code out there that I can reference? Am new to Android so it's a steep learning curve coming from WinCE to Android.

appreciate the assistance :-)

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Darryn Campbell
I can't find anything

I can't find anything official but I think you want something like the following:

    editText = FindViewById(Resource.Id.editText);    
    editText.KeyPress += (object sender, View.KeyEventArgs e) => 
    {
        e.Handled = false;
        if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter)
        {
            //your logic here
            e.Handled = true;
        }
    };

From: https://stackoverflow.com/questions/16090143/xamarin-android-edittext-enter-key/27079741 (that question is asking about something different but the answer copied above should work for you... just replace e.keycode with the key code of your choice) 

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Patrick Kennedy
Thanks again for the prompt

Thanks again for the prompt reply Darryn. There's seems to be a lot of frustration out there when it comes to this topic. I still have 2 questions.

1. The code above that you have supplied. Where exactly do I place this in the Xamarin Forms content page?
2. FindViewById. What NuGet package do i need to import to see this method? I am using Visual Studio 2017.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Darryn Campbell
1. The code above that you

1. The code above that you have supplied. Where exactly do I place this in the Xamarin Forms content page?

The code goes in the .cs file associated with the form

2. FindViewById. What NuGet package do i need to import to see this method? I am using Visual Studio 2017.

FindViewById is a method of Android Activity, you should not need a separate Nuget package: https://docs.microsoft.com/en-us/dotnet/api/android.app.activity.findviewbyid?view=xamarin-android-sdk-9

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments