External keyboard input on android

It seems like key_trigger inputs aren’t working as it should on Android from an external bluetooth keyboard.

Based on the Getting started Tutorial, I changed the input to do be like this for testing purposes:

function on_input(self, action_id, action)
    if action_id == hash("jump") then
        jump(self)
    elseif action_id == hash("abortjump") then
        abort_jump(self)
    end
end

The keybindings are like this:

key_trigger {
  input: KEY_SPACE
  action: "jump"
}
key_trigger {
  input: KEY_ENTER
  action: "abortjump"
}
key_trigger {
  input: KEY_UP
  action: "jump"
}
key_trigger {
  input: KEY_DOWN
  action: "abortjump"
}

Hitting Enter on the bluetooth keyboard triggers the ‘jump’ action multiple times like the key is ‘stuck’ down. All the other keys seem to go into ‘void’.

I’ve tested on Galaxy S4, Xperia Z5 and Galaxy Tab 2.

I’m unsure if this is a feature request or a bug.

I’ve also tried both KeyEvent and HiddenInputField in the project settings, same result for both.

2 Likes

I’m pretty sure what’s happening there is that the android bluetooth keystroke is getting interpreted as a ‘touch’ event, since in input/game.input_binding that example project has ‘touch-multi’ set to fire a ‘touch’ action under ‘touch triggers’. If you remove that trigger I wonder if you’d have any actions triggered at all from the bt keyboard.

I noticed the same thing when trying to bind actions to android gamepad input.

You can bind to the android ‘back’ button with the ‘key-back’ under ‘key triggers’, but I wonder if it’s possible to bind to other android inputs?

You’re not checking action.released in your code so it will send input events from the moment you press the key until you release it. Shouldn’t your on_input look like this:

function on_input(self, action_id, action)
    if action_id == hash("jump") and action.released then
        jump(self)
    elseif action_id == hash("abortjump") and action.released then
        abort_jump(self)
    end
end

But I don’t think we’ve ever tried connecting a bluetooth keyboard to an Android device so there might still be issues there…