Android Input

I’ve started looking at my Android port’s input. First of all, I noticed that the touchscreen seems to emulate a “mouse”, which is awesome. So the mouse just works already. However, what happens if I start handling touch input events? How does that affect the “mouse”?

Second, I am having to use an emulator to test keyboard stuff, because I don’t have access to any Android devices with hardware keyboards. I got the hardware keys (Back, etc.) working with SDL_SCANCODE_AC_BACK etc. I make use of things like SDL_SCANCODE_UP for menu navigation and in-game controls as well. I thought that these would just work, but at least on the emulator I can’t seem to get anything to happen. When I press an emulated dpad button, nothing happens. The other (aside from directional) keys seem to be working. The keys that my menus use are the ones I have tested so far: SDL_SCANCODE_RETURN, SDL_SCANCODE_BACKSPACE, and SDL_SCANCODE_TAB. These all work. It seems like maybe the directional keys are the only ones not working. Does the dpad usually work? Could this just be an emulator issue?

Finally, I use SDL_TEXTINPUT to get text when an editable text box is selected. In Android, typing letters and numbers doesn’t cause anything to happen. Does this even work on Android?

I hope this isn’t too much stuff for one thread. One last question: Is there anywhere where I can read up on answers to any of this stuff? I’ve looked and found nothing. I have already read the android readme in the source, and done a lot of googling (and forum searching). Thanks!

2014-06-22 2:54 GMT-03:00 Dark_Oppressor :

I’ve started looking at my Android port’s input. First of all, I noticed
that the touchscreen seems to emulate a “mouse”, which is awesome. So the
mouse just works already. However, what happens if I start handling touch
input events? How does that affect the “mouse”?

If you want to handle touch events, you can just ignore mouse events. If
your app is multi platform you probably need some ifdefs.

Second, I am having to use an emulator to test keyboard stuff, because I
don’t have access to any Android devices with hardware keyboards. I got the
hardware keys (Back, etc.) working with SDL_SCANCODE_AC_BACK etc. I make
use of things like SDL_SCANCODE_UP for menu navigation and in-game controls
as well. I thought that these would just work, but at least on the emulator
I can’t seem to get anything to happen. When I press an emulated dpad
button, nothing happens. The other (aside from directional) keys seem to be
working. The keys that my menus use are the ones I have tested so far:
SDL_SCANCODE_RETURN, SDL_SCANCODE_BACKSPACE, and SDL_SCANCODE_TAB. These
all work. It seems like maybe the directional keys are the only ones not
working. Does the dpad usually work? Could this just be an emulator issue?

DPAD events reported as SOURCE_DPAD get reported by SDL as joystick events.
If Android reports them as SOURCE_KEYBOARD we report them as key presses.

Finally, I use SDL_TEXTINPUT to get text when an editable text box is
selected. In Android, typing letters and numbers doesn’t cause anything to
happen. Does this even work on Android?

Did you issue https://wiki.libsdl.org/SDL_StartTextInput ?

I hope this isn’t too much stuff for one thread. One last question: Is
there anywhere where I can read up on answers to any of this stuff? I’ve
looked and found nothing. I have already read the android readme in the
source, and done a lot of googling (and forum searching). Thanks!

Sadly many of these things are documented only in the source code (or
worse, developers’ heads :wink: ).–
Gabriel.

You can also differentiate between real mouse events and those simulated
by the touch input by checking event.(button/motion/wheel).which for the
value SDL_TOUCH_MOUSEID.

Jonny DOn Sun, Jun 22, 2014 at 9:49 AM, Gabriel Jacobo wrote:

2014-06-22 2:54 GMT-03:00 Dark_Oppressor :

I’ve started looking at my Android port’s input. First of all, I noticed

that the touchscreen seems to emulate a “mouse”, which is awesome. So the
mouse just works already. However, what happens if I start handling touch
input events? How does that affect the “mouse”?

If you want to handle touch events, you can just ignore mouse events. If
your app is multi platform you probably need some ifdefs.

Second, I am having to use an emulator to test keyboard stuff, because I
don’t have access to any Android devices with hardware keyboards. I got the
hardware keys (Back, etc.) working with SDL_SCANCODE_AC_BACK etc. I make
use of things like SDL_SCANCODE_UP for menu navigation and in-game controls
as well. I thought that these would just work, but at least on the emulator
I can’t seem to get anything to happen. When I press an emulated dpad
button, nothing happens. The other (aside from directional) keys seem to be
working. The keys that my menus use are the ones I have tested so far:
SDL_SCANCODE_RETURN, SDL_SCANCODE_BACKSPACE, and SDL_SCANCODE_TAB. These
all work. It seems like maybe the directional keys are the only ones not
working. Does the dpad usually work? Could this just be an emulator issue?

DPAD events reported as SOURCE_DPAD get reported by SDL as joystick
events. If Android reports them as SOURCE_KEYBOARD we report them as key
presses.

Finally, I use SDL_TEXTINPUT to get text when an editable text box is
selected. In Android, typing letters and numbers doesn’t cause anything to
happen. Does this even work on Android?

Did you issue https://wiki.libsdl.org/SDL_StartTextInput ?

I hope this isn’t too much stuff for one thread. One last question: Is
there anywhere where I can read up on answers to any of this stuff? I’ve
looked and found nothing. I have already read the android readme in the
source, and done a lot of googling (and forum searching). Thanks!

Sadly many of these things are documented only in the source code (or
worse, developers’ heads :wink: ).


Gabriel.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

gabomdq wrote:

If you want to handle touch events, you can just ignore mouse events. If your app is multi platform you probably need some ifdefs.

Oh of course, thanks!

gabomdq wrote:

DPAD events reported as SOURCE_DPAD get reported by SDL as joystick events. If Android reports them as SOURCE_KEYBOARD we report them as key presses.

Are those joystick events not part of an actual joystick device? Because the only joystick showing up is the accelerometer.
I found this:

Code:
/* D-Pad key codes (API 1) */
case AKEYCODE_DPAD_UP:
button = SDL_CONTROLLER_BUTTON_DPAD_UP;
break;
case AKEYCODE_DPAD_DOWN:
button = SDL_CONTROLLER_BUTTON_DPAD_DOWN;
break;
case AKEYCODE_DPAD_LEFT:
button = SDL_CONTROLLER_BUTTON_DPAD_LEFT;
break;
case AKEYCODE_DPAD_RIGHT:
button = SDL_CONTROLLER_BUTTON_DPAD_RIGHT;
break;

gabomdq wrote:

Did you issue?https://wiki.libsdl.org/SDL_StartTextInput (https://wiki.libsdl.org/SDL_StartTextInput) ?

Wow, ya that was the problem. I set that up, and now when there is a hardware keyboard present, it works. If there is no hardware keyboard, the software keyboard pops up. Awesome!
Code:

Code:>

Apologies, that last post got a bit messed up. I prematurely posted it.

It was finished, except I was going to say about those dpad events: I found the “AKEYCODE_DPAD_X becomes SDL_CONTROLLER_BUTTON_DPAD_X” stuff. Is that what you were referring to? I already grab those in my engine anyway. I wonder if the emulator is just being wonky.

Oh! I thought of one more question: How is a trackball handled? I didn’t even know Android devices HAD those, but I noticed it in the emulator config as a hardware option.

2014-06-22 18:20 GMT-03:00 Dark_Oppressor :

DPAD events reported as SOURCE_DPAD get reported by SDL as joystick
events. If Android reports them as SOURCE_KEYBOARD we report them as key
presses.

Are those joystick events not part of an actual joystick device? Because
the only joystick showing up is the accelerometer.
I found this:

They get reported as Android reports it. If Android sends a source "DPAD"
from a device id, we report that to the app. If it sends source “KEYBOARD”,
we send it as a keyboard event. Maybe we need to send DPAD events as
KEYBOARD only, not as joystick.

Ganroe;/

OK, well, thanks!