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

I’m not actually using the keyboard for text input, I’m using it as a USB game controller (the game involves inputting numbers), so it’s a USB number pad like this one

31

However, I am getting no response. Just to make things as clear as possible, I have a play_sound triggered by each number which isn’t working. The other sounds do work in the game on the android device, and on my mac, the number keys correctly play the sound when i bundle it on my mac.

oh GODDDDDD i have solved it.

In input it has to be “key-kp-9” and not “key-9” because i am using a numpad. sorry, a “keypad”.

I hate computers so much some time ahah

3 Likes

Okay, I am officially marking this as unsolved. The mouse icon is no longer a problem, but i do need to get input from the USB controllers connected to an android device via OTG.

I have created an APK specifically for testing input. Various sprites appear and disappear when you press certain keys, and there is also a label that shows which key is being pressed. This works perfectly on my mac using the same USB devices.

On my Android devices (both of them), the USB controllers ( a keypad and a makey makey) work fine outside of the testing APK. i.e. i can use them to search on google and navigate etc. The testing APK i created appears to work fine as well (when you touch the screen, for example, the “mouse input” sprite lights up). But it doesn’t accept input from the numeric keypad or the makey makey.

I have tried plugging in the devices in a different order, have tried plugging in one at a time, tried using an external battery to power them, etc. etc…

Can you think of anything I may have missed? Are there any issues related to selecting the type of keyboard in the google settings? I got a notification everytime i plugged the keyboard in until i eventually selected English-International, and I think… though I can’t be sure… that might be related.

If you in a script print any input you get, do you get any output when pressing keys on the connected controllers?

On my mac, yes. On the android device I don’t know how to print or where the log would be found.

The fact that touching the screen causes the correct sprite to light up (but simulating a mouse click via the makey makey doesn’t) makes me think the code is not the problem. Also, the same code works on my mac.

I’ve just seen this:

18

could it be related ?

Perhaps the numpad you’re using generates some kind of key events on Android that we do not support, just like the Amazon Fire TV remote discussed here.

I find that to be somewhat unlikely, as the keypad is very generic, unlike the Amazon fire TV remote which is pretty specific. I mean… it’s number keys. That shouldn’t be a problem, should it??

The makey makey, for all its weirdness, really only sends key presses and mouse clicks.

Furthermore, the fact that neither of the controllers work makes me think that it’s more likely to be defold (or some problem with me) than the controller.

Is there anyway I could find out what key events are being generated and whether or not they are interpreted by defold or not?

Well, three hours later I can confirm that this problem is beyond my current understanding. A quick summary of the situation so far:

I am unable to control an android app using a numeric keypad or a generic keyboard connected using a USB-OTG cable, even though both work well to control the android OS

  • I have created a “tester” app, which takes input and uses it to control the tint.w of some sprites, and prints to the console.

  • On my mac, the tester works perfectly with both the numpad and the generic keyboard.

  • On the android devices, the numeric keypad and the keyboard both work fine controlling the Android OS.

  • The tester (bundled as an APK) runs fine on both Android devices and is able to correctly detect a screen touch as a mouse click. The generic keyboard (which is actually a makey makey) has a mouse click function, via which I am also able to trigger the mouse click input in the tester app.

  • However, the app does not respond to the numeric keypad at all, or the other functions of the makey makey (up, down, left, right, space bar, W, A, S, D, F, G).

I am going to try and do some android debugging but I would very much appreciate some help if anyone feels they are able to shed any light.

I’m pretty sure this is our fault. It sounds like you’re doing everything right. I’ll take a look and talk to @sven about this tomorrow.

This is exactly what I was hoping you would say!! Thanks Britzl!

I hate to be that guy, but… this is kind of important!

I was kind of keeping this secret because i wanted to do a big reveal, but, I am basically creating a real-life version of the game Keep Talking and Nobody Explodes.. Which means I am making a kind of 1980’s bomb inside a suitcase using all recycled elements. My desk right now looks like this:

The plan is to control everything from an old android phone, with an external battery powering a makey makey and the numeric keypad. It all fits inside a 1992 Samsonite suitcase. Using the makey makey, I am able to “trigger” a sound effect when the case is opened and make the screen flash green. I cannot even begin to explain how cool that is going to look (this is how it is going to sound). There is also a locked box with vital information inside (you have to disconnect the right cable at the right time to be able to get the key), 3 mechanical switches (that control the the makey makey) and the whole game ends when you disconnect a massive coiled cable from the “explosives”. The making of this so far has involved soldering, carpantery, recycling, research… etc, etc, etc… the programming itself was the easiest part!!!

I will debut it at a DIY zine event on the 16th of march and I am in the final steps. Once I can get the keypad and makey makey to communicate with the phone, my next step is playtesting with my flatmates. So, I have hit a pretty major roadblock today!!!

Thanks Britzl for offering to help with this issue which I am aware will affect very few people! and I look forward to your response tomorrow. Please let me know if I am able to help!

6 Likes

Any news @britzl?! I am very curious about this!

thankyousorrythankyou

Hi! The only news I have so far is that I talked to the team today and Mathias and Sven poked around the Android input code. I also went out and bought:

Me and Sven are traveling to our Malmö office tomorrow and I’m pretty sure we’ll be able to get at least a little bit of time to take a closer look at this. If not during the day, then maybe in the hotel lobby over a beer!

I’ll also set everything up tonight for a bit of testing on my own.

2 Likes

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.