Can you make android apps built in defold accept key inputs? (SOLVED!)

I have a feeling that I am working endlessly on this one thing when, for somebody else, it might just be a few hours work to create a native extension. My goal is a simple one:

To allow apps built in defold to accept key inputs (not text input), in order to control an android device via a numeric keypad and a generic keyboard (a makey makey) via USB OTG in the same way that you can control them on a mac/pc/whatever.

If you believe you are able to help please get in touch (88.josh@gmail.com) so we can talk about time, money, and exactly what it is I need.

As I said, I think that this will (hopefully) be a fairly simple problem for someone with the right skill set. I do not have that skill set and I don’t even really know what it is.

Many thanks and looking forward to a dirge of offers!

Hi ,
I am a experienced developer and would be able to help you out on this…
I sent you an email
Best Wishes,
Andrew
andrewjohnson56782@gmail.com

2 Likes

Hi! I didn’t get your mail, but I sent you one just now. Thanks for your reply.
Josh

2 Likes

I am still looking for someone to help out with this! It could be you! !

1 Like

I believe what you are trying to do is not possible with the current Defold API. It would be great if we had a way of simulating input events, but we don’t and any amount of throwing money at the problem won’t solve it.

Hi! Do you mean it would be impossible, even with a native extension? Because I am going to spend quite a lot of time today learning c++ and trying to do exactly that!

It would be impossible even with a native extension. At least if you want to use Defold’s input system (the whole on_input shenanigan). If you want to register a simple Lua callback that gets fired whenever a key is pressed, you can do that with NE, but it won’t go through Defold’s input system.

You can find examples of how to register callbacks here:

or here:

2 Likes

Defold’s input system is not top priority here! Luckily the control system I need is actually fairly simple on the programming side. I just need a true/false boolean to say whether a key is pressed (or a message on key.pressed and key.released).

Thanks for giving me a good intro on how this might work. I’ll be back very soon with even more questions.

Edit: it should of course also be clear that I expect to know which key is being pressed or released. I need one Boolean for each key_event.

2 Likes

Hold on @88.josh! I’m working on Android key triggers as we speak. I got most of it working already. I need to test some more, perhaps make a tweak or two and then get it approved by the engine dev technomancers. Once that’s done it will be available a a normal alpha build.

6 Likes

@britzl

GIF-Glad-Joy-crying-happy-cry-GIF

3 Likes

… i hate to ask. But how long are you expecting this to take? I have to consider what other options are available. Deadline is Friday 16th (and Saturday 17th is launch day!!!) So i’m right on the wire

Hopefully @sven has time to take a look at my PR on Monday. Once it’s accepted and merged it will show up in an alpha build within a few hours. Not sure about the release flow of the new editor though. You might have to build with bob or editor 1.

1 Like

If it doesn’t require changes to editor 2 we can surely make an alpha/dev build in time.

2 Likes

wow guys, I don’t know what to say!

I really appreciate all your hard work.

1 Like

My PR has now been merged. Once the build system has done it’s work it should be available from d.defold.com in the alpha channel.

4 Likes

That’s great! This has turned out much cheaper than I expected!!!
I’ll check it out this evening.

Thanks!

Josh

3 Likes

IT WORKS!!!
IT WORKS!!!
IT WORKS!!!

So, at the moment I am being quite cautious because I’ve only checked with the keypad, not the makey
makey, but it would appear that @britzl’s kind work has paid off. Coincidentally, I just found out that if you put more than three exclamation marks, the forum only allows you to print three of them.

4 Likes

Yay!

I have no idea what kind of key events that are generated by a makey makey, but I’ve mapped all of the keys that we have a Defold mapping for. These are the ones that have received a key trigger mapping in Defold (and a-z and 0-9 ofc):

case AKEYCODE_ESCAPE: _glfwInputKey( GLFW_KEY_ESC, glfw_action ); return 1;
case AKEYCODE_F1: _glfwInputKey( GLFW_KEY_F1, glfw_action ); return 1;
case AKEYCODE_F2: _glfwInputKey( GLFW_KEY_F2, glfw_action ); return 1;
case AKEYCODE_F3: _glfwInputKey( GLFW_KEY_F3, glfw_action ); return 1;
case AKEYCODE_F4: _glfwInputKey( GLFW_KEY_F4, glfw_action ); return 1;
case AKEYCODE_F5: _glfwInputKey( GLFW_KEY_F5, glfw_action ); return 1;
case AKEYCODE_F6: _glfwInputKey( GLFW_KEY_F6, glfw_action ); return 1;
case AKEYCODE_F7: _glfwInputKey( GLFW_KEY_F7, glfw_action ); return 1;
case AKEYCODE_F8: _glfwInputKey( GLFW_KEY_F8, glfw_action ); return 1;
case AKEYCODE_F9: _glfwInputKey( GLFW_KEY_F9, glfw_action ); return 1;
case AKEYCODE_F10: _glfwInputKey( GLFW_KEY_F10, glfw_action ); return 1;
case AKEYCODE_F11: _glfwInputKey( GLFW_KEY_F11, glfw_action ); return 1;
case AKEYCODE_F12: _glfwInputKey( GLFW_KEY_F12, glfw_action ); return 1;
case AKEYCODE_DPAD_UP: _glfwInputKey( GLFW_KEY_UP, glfw_action ); return 1;
case AKEYCODE_DPAD_DOWN: _glfwInputKey( GLFW_KEY_DOWN, glfw_action ); return 1;
case AKEYCODE_DPAD_LEFT: _glfwInputKey( GLFW_KEY_LEFT, glfw_action ); return 1;
case AKEYCODE_DPAD_RIGHT: _glfwInputKey( GLFW_KEY_RIGHT, glfw_action ); return 1;
case AKEYCODE_SHIFT_LEFT: _glfwInputKey( GLFW_KEY_LSHIFT, glfw_action ); return 1;
case AKEYCODE_SHIFT_RIGHT: _glfwInputKey( GLFW_KEY_RSHIFT, glfw_action ); return 1;
case AKEYCODE_CTRL_LEFT: _glfwInputKey( GLFW_KEY_LCTRL, glfw_action ); return 1;
case AKEYCODE_CTRL_RIGHT: _glfwInputKey( GLFW_KEY_RCTRL, glfw_action ); return 1;
// This key is not {@link AKEYCODE_NUM_LOCK}; it is more like {@link AKEYCODE_ALT_LEFT}.
// https://android.googlesource.com/platform/frameworks/native/+/master/include/android/keycodes.h
case AKEYCODE_NUM: _glfwInputKey( GLFW_KEY_LALT, glfw_action ); return 1;
case AKEYCODE_ALT_LEFT: _glfwInputKey( GLFW_KEY_LALT, glfw_action ); return 1;
case AKEYCODE_ALT_RIGHT: _glfwInputKey( GLFW_KEY_RALT, glfw_action ); return 1;
case AKEYCODE_TAB: _glfwInputKey( GLFW_KEY_TAB, glfw_action ); return 1;
case AKEYCODE_INSERT: _glfwInputKey( GLFW_KEY_INSERT, glfw_action ); return 1;
case AKEYCODE_DEL: _glfwInputKey( GLFW_KEY_DEL, glfw_action ); return 1;
case AKEYCODE_ENTER: _glfwInputKey( GLFW_KEY_ENTER, glfw_action ); return 1;
case AKEYCODE_PAGE_UP: _glfwInputKey( GLFW_KEY_PAGEUP, glfw_action ); return 1;
case AKEYCODE_PAGE_DOWN: _glfwInputKey( GLFW_KEY_PAGEDOWN, glfw_action ); return 1;
case AKEYCODE_MOVE_HOME: _glfwInputKey( GLFW_KEY_HOME, glfw_action ); return 1;
case AKEYCODE_MOVE_END: _glfwInputKey( GLFW_KEY_END, glfw_action ); return 1;
case AKEYCODE_NUMPAD_0: _glfwInputKey( GLFW_KEY_KP_0, glfw_action ); return 1;
case AKEYCODE_NUMPAD_1: _glfwInputKey( GLFW_KEY_KP_1, glfw_action ); return 1;
case AKEYCODE_NUMPAD_2: _glfwInputKey( GLFW_KEY_KP_2, glfw_action ); return 1;
case AKEYCODE_NUMPAD_3: _glfwInputKey( GLFW_KEY_KP_3, glfw_action ); return 1;
case AKEYCODE_NUMPAD_4: _glfwInputKey( GLFW_KEY_KP_4, glfw_action ); return 1;
case AKEYCODE_NUMPAD_5: _glfwInputKey( GLFW_KEY_KP_5, glfw_action ); return 1;
case AKEYCODE_NUMPAD_6: _glfwInputKey( GLFW_KEY_KP_6, glfw_action ); return 1;
case AKEYCODE_NUMPAD_7: _glfwInputKey( GLFW_KEY_KP_7, glfw_action ); return 1;
case AKEYCODE_NUMPAD_8: _glfwInputKey( GLFW_KEY_KP_8, glfw_action ); return 1;
case AKEYCODE_NUMPAD_9: _glfwInputKey( GLFW_KEY_KP_9, glfw_action ); return 1;
case AKEYCODE_NUMPAD_DIVIDE: _glfwInputKey( GLFW_KEY_KP_DIVIDE, glfw_action ); return 1;
case AKEYCODE_NUMPAD_MULTIPLY: _glfwInputKey( GLFW_KEY_KP_MULTIPLY, glfw_action ); return 1;
case AKEYCODE_NUMPAD_SUBTRACT: _glfwInputKey( GLFW_KEY_KP_SUBTRACT, glfw_action ); return 1;
case AKEYCODE_NUMPAD_ADD: _glfwInputKey( GLFW_KEY_KP_ADD, glfw_action ); return 1;
case AKEYCODE_NUMPAD_DOT: _glfwInputKey( GLFW_KEY_KP_DECIMAL, glfw_action ); return 1;
case AKEYCODE_NUMPAD_EQUALS: _glfwInputKey( GLFW_KEY_KP_EQUAL, glfw_action ); return 1;
case AKEYCODE_NUMPAD_ENTER: _glfwInputKey( GLFW_KEY_KP_ENTER, glfw_action ); return 1;
case AKEYCODE_NUM_LOCK: _glfwInputKey( GLFW_KEY_KP_NUM_LOCK, glfw_action ); return 1;
case AKEYCODE_CAPS_LOCK: _glfwInputKey( GLFW_KEY_CAPS_LOCK, glfw_action ); return 1;
case AKEYCODE_SCROLL_LOCK: _glfwInputKey( GLFW_KEY_SCROLL_LOCK, glfw_action ); return 1;
case AKEYCODE_META_LEFT: _glfwInputKey( GLFW_KEY_LSUPER, glfw_action ); return 1;
case AKEYCODE_META_RIGHT: _glfwInputKey( GLFW_KEY_RSUPER, glfw_action ); return 1;
case AKEYCODE_BREAK: _glfwInputKey( GLFW_KEY_PAUSE, glfw_action ); return 1;
case AKEYCODE_DPAD_CENTER: _glfwInputKey( GLFW_KEY_ENTER, glfw_action ); return 1;
case AKEYCODE_STAR: _glfwInputKey( '*', glfw_action ); break;
case AKEYCODE_POUND: _glfwInputKey( '#', glfw_action ); break;
case AKEYCODE_COMMA: _glfwInputKey( ',', glfw_action ); break;
case AKEYCODE_PERIOD: _glfwInputKey( '.', glfw_action ); break;
case AKEYCODE_SPACE: _glfwInputKey( GLFW_KEY_SPACE, glfw_action ); break;
case AKEYCODE_GRAVE: _glfwInputKey( '`', glfw_action ); break;
case AKEYCODE_MINUS: _glfwInputKey( '-', glfw_action ); break;
case AKEYCODE_EQUALS: _glfwInputKey( "=", glfw_action ); break;
case AKEYCODE_LEFT_BRACKET: _glfwInputKey( '[', glfw_action ); break;
case AKEYCODE_RIGHT_BRACKET: _glfwInputKey( ']', glfw_action ); break;
case AKEYCODE_BACKSLASH: _glfwInputKey( '\\', glfw_action ); break;
case AKEYCODE_SEMICOLON: _glfwInputKey( ';', glfw_action ); break;
case AKEYCODE_APOSTROPHE: _glfwInputKey( '\'', glfw_action ); break;
case AKEYCODE_SLASH: _glfwInputKey( '/', glfw_action ); break;
case AKEYCODE_AT: _glfwInputKey( '@', glfw_action ); break;
case AKEYCODE_PLUS: _glfwInputKey( '+', glfw_action ); break;
5 Likes

Makey Makeys send up, down, left, right, WASDFG, space, and mouse clicks. There are also some other mouse functions that i am not using and do not understand. But everything works fine (at least, the functions that I am using all work fine!)

3 Likes