3

I have a custom Android device that has additional hardware buttons. Those buttons are used to trigger a barcode scanner on the device.

I am trying to trigger the keypress from code so far i tried:

MainActivity.Instance.DispatchKeyEvent ( new Android.Views.KeyEvent(
   Android.Views.KeyEventActions.Down, 
   Android.Views.Keycode.Eisu
));

Eisu is 211 which is my button's keycode.

But this gives me nothing. Has anyone managed this?

Edit

I also tried with instrumentation:

await Task.Run (delegate {
   Instrumentation inst = new Instrumentation();
   inst.SendKeyDownUpSync (Android.Views.Keycode.Eisu);
});

No luck on this... I am guessing that the events get dispatched but somehow no context catches them.

This is called from DependencyService in xamarin.forms, could it be a problem?

Community
  • 1
  • 1
Jmorvan
  • 1,020
  • 11
  • 31
  • [Android Simulate Key Press here on stack overflow](http://stackoverflow.com/questions/8696489/android-simulate-key-press) ... [Xamarin api for Instrumentation](http://androidapi.xamarin.com/?link=M%3aAndroid.App.Instrumentation.SendKeyDownUpSync(Android.Views.Keycode)) – arnfada Jan 30 '15 at 13:17
  • Thanks, Actually I did try this, see my update. – Jmorvan Jan 30 '15 at 13:45
  • Nobody knows the answer to this? – Denis Vitez Nov 12 '18 at 13:24

0 Answers0