Defold app won't accept keyboard input on android device via USB-OTG (SOLVED)

Give me your email if you like and i’ll add you as a collaborator on the input tester!

bjorn.ritzl@king.com

Okay! I have added you. As it stands, the bootstrap collection is the tester. Look in /main/tester.collection to see. It’s very simple, and you can ignore the other collections. All you need to do is build it to test it. Good luck!

Thanks for the invite. I did end up with my own test app with every possible input bound to an action. Some observations from running on an HTC One M9, Android 7.1 and a Targus numpad:

  • The keys / * - + and 000 all generate TEXT events.
  • Enter and Backspace detects a pressed but not a released event
  • The numbers does nothing at all

When tested in the Android OS the number keys only act as navigation (up, down, left, right, pg up, etc). And it ignores if Numlock is active or not.

This makes me think that in my case the number keys generate the same kind of key events as the Amazon Fire TV remote. I’m guessing it’s the DPAD key events (https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_DPAD_LEFT).

Is your numeric keyboard generating numbers in other apps when pressing 0-9?

Yes. In both of my android devices, I can toggle NumLock to use arrow keys or numbers as I wish (in the android OS). I am using a Moto G3 and a Moto G4. The G4 is running android 7.0. the G3, something slightly older.

I am going to try building a HTML5 and getting that running on Chrome on the android device. Is that likely to help?

Have you bound a text action in your input bindings? I got some key presses from the numpad that way.

I don’t know what that means
edit: Okay, I see what that means and will investigate that.

But i expect that the input from the makey makey (basically a generic gamepad with the letters W A S D F and G, a space bar, a 4 way d-pad, and a right click) won’t work? Or, at least, the D-Pad won’t work. right click already works and the letters and space bar can probably work as text input

Yes, this:

I guess this should work for basic key input like 0-9 on the numpad. BUT we should also support Android key events to Key Triggers.

Yes, this is likely true. We need to wait for the Android key event to Key Triggers to get that to work.

Since you’re in a rush I wonder if you could move faster with a native extension that forwards key events to Lua?

Takk for all your help (takk? is that right?!) Britzl! I really appreciate it.

At the moment I am going to investigate the possibility of adapting my hardware. I know it’s possible to hack the makey makey ( this just in case anyone has read this far without knowing what it is ) so I could probably change the D pad to assign it to some other key presses.

If that doesn’t work, I am going to try and run the game in HTML5 on Chrome on Android OS to see if key inputs are passed correctly that way.

If anyone has any idea how a native extension might be built for this task (letting defold correctly interpret key presses from a keyboard connected to an android device via USB-OTG) I would be interested in hearing about it!

If none of the above work I am going to set fire to all of my personal possessions and go and live in the woods.

2 Likes

Almost, it’s tack!

We wouldn’t want this to happen.

1 Like

Okay, next question.

I have done this
14

and this
36

But I am not printing anything when I press the key assigned to a text input (on my mac!)

edit: Sorted it now. I cannot even begin to describe how accurate this meme is:

You should only have one text trigger. When keyboard input is detected it will end up in the action_id you assigned to the text trigger and the key pressed in action.text

1 Like

Okay! Just a quick update for those still paying attention:

the text trigger method did work and I was able to get the keypad working with the android app to some extent…

…but not to the extent that is necessary for my game. text triggers don’t have action.released, action.pressed, or action.repeated. And those are vital for me, because each “cable” in my “bomb” is a completed circuit attached to the makey makey. The computer interprets this as a key being held down. Just like in those old Bond films, you have to disconnect the cables in the correct order (=the computer must receive the action.released in the correct order) in order to avoid the explosion sound effect that signals your doom. I am going to continue experimenting, this time focusing getting a HTML bundle and playing it in the chrome browser on the android device.

Wish me luck!

3 Likes

Quick question:

Are android key events like to be included in defold in the near future? and, how near is that future?

I’m afraid it’s probably not soon enough for you. We’re releasing 1.2.123 soon and that means it’s two weeks until next release.

I could take a look at the code tomorrow and get started on the work but I can’t make any promises.

2 Likes

HTML5 apps created in defold accept android key events when played in the browser of an android device!

YES

there’s just no sound and everything is very slow.

Okay next question: what tool exists on the internet that can convert an HTML5 file into an android APK?

3 Likes

Just to update this thread as well so there are no doubts: Apps built in defold now correctly interpret key presses from USB OTG devices, at least in the alpha build that Britzl has sent to me. I expect these changes will be included in the main build soon. So i’m joyfully marking this as solved.

Excellent! I’m happy that the solution worked out well for you. The Android key trigger support will show up in Defold 1.2.124

1 Like