Sending Generic.kl key commands

Hello,

I have a Leonardo Arduino and I would like to have it execute commands specified in the Android Generic.kl library.

I am using the Android as an auto headunit and I would like to have it sleep when the accessory switch is off.

Does anyone have any experience with this, I have been unable to find a method.

Thanks,
-Erik

Hi Erik,

We are not certain we completely understand your question.

We’ve had a quick look at this and it seems to be a way to define keys/inputs from standard interfaces, such as keyboards, joysticks, etc.

In this case, a simple solution would most likely to have the Leonardo act like a keyboard (or other HID compatible device), such as mentioned here.

Sincerely,

Thanks for the reply Sébastien. Sorry about not being clearer, hope this helps.

All I am really trying to do is execute some of the key codes specified in the androids Generic.kl file via the Leonardo.

The reason I am confused is that if I send the command via my windows laptop to the android I need to enter a shell in the android via adb (adb shell input keyevent ), and then I can send the keycode via input.

I was not sure how this would work if an Android was driving, do I first need to setup an android shell entry command and then send the keycode? I will try the links that you sent.

Thanks,
-Erik

Hi,

Since the Leonardo can present itself as a USB HID device, a simple solution would be to make it do just that,. If your Android device can work as a USB host you can then simply connect your Leonardo by USB to the smart device.

For example, if you make the Leonardo work as an external keyboard then you can most likely simply send key codes as needed directly to whatever is the current interface.

Sincerely,

Hi Sébastien

I tried that last night and I can get the android to sleep but it will not wake up. My PC will sleep and wake up but not the android. Do you know if an android can wake up from S3 via the keyboard, I guess this might be android specific.

Thanks again,
-Erik

Hi Erik,

To be honest, I have not tried to do anything related to sleep/waking with Android. It would probably be best for you to post about this on an Android specific forum (or at least first search there for more info).

Do post back here if you figure out anything else though, as this will certainly be interesting to the RobotShop community as a whole!

Sincerely,

Hello Sébastien,

Yah, I tried an android forum and no one seemed to be interested in answering, Will let you know what I find out. thanks for the help.

-Erik

Hi,

We did search a bit, but mostly found hardware-specific information that is not helpful for your situation. We also found plenty of people who were trying to prevent wake-up from keyboards (usually wireless/Bluetooth) on Android devices!

This may be interesting though: askubuntu.com/questions/848698/wake-up-from-suspend-using-wireless-usb-keyboard-or-mouse-for-any-linux-distro
It implies that in some cases your hardware may simply have settings that set the USB ports to also sleep when the device does, therefore preventing wake-up from things such as a USB keyboard.

It may be worth looking into the various hardware and software related solutions, as this situation may yet be more complex than a simple command being sent.

Sincerely,

Wow, thank you Sébastien for looking into this! I will take a look at the link and see if that helps me. I appreciate all the effort.

-Erik