Touch input events on Android

Hello,

I have been unable to process any touch input events on my android devices. Keyboard input on the other hand works just fine. I have debugged it so far by putting a System.exit() statement in the onNativeTouch() function in SDLActivity.java which causes the program to exit as soon as the screen is touched. I then removed that statement and further debugged by adding exit(0); to Java_org_libsdl_app_SDLActivity_onNativeTouch in src/core/android/sdl_android.c which exited in the same fashion as the Java code. So it appears that SDL is receiving touch events. However, when I check with the following code I get nothing. Am I doing something wrong or missing something obvious?

if (SDL_PollEvent(&inputEvent))
{
int numTouch = SDL_GetNumTouchDevices();
logMsg ("numTouch = " +Ogre::StringConverter::toString(numTouch));
//exit(0);

// Ogre::LogManager::getSingletonPtr()->logMessage(“Crash??”);

    switch (inputEvent.type)
    {
        case SDL_WINDOWEVENT:
            logMsg("windowevent!");
            exit(0);
            break;
        case SDL_FINGERMOTION:
            logMsg("Motion!");
            exit(0);
            // processes touch input
            if (processUnbufferedTouchInput() == false)
            {
                return false;
            }
            break;
        case SDL_FINGERDOWN:
            logMsg("Finger Down!");
            exit(0);
            // processes touch input
            if (processUnbufferedTouchInput() == false)
            {
                return false;
            }
            break;
        case SDL_FINGERUP:
            logMsg("Finger Up!");
            exit(0);
            // processes touch input
            if (processUnbufferedTouchInput() == false)
            {
                return false;
            }
            break;
        case SDL_MULTIGESTURE:
            logMsg("Multigesture!");
            exit(0);
            // processes touch input
            if (processUnbufferedTouchInput() == false)
            {
                return false;
            }
            break;
       
        case SDL_TEXTINPUT:
            keyPressed = "";
            if (processUnbufferedKeyInput(true) == false)
            {
                return false;
            }
            
            break;
            /*
        case SDL_KEYDOWN:
			logMsg("Keydown!");
            if (processUnbufferedKeyInput(false) == false)
            {
                return false;
            }
            break;
            
        case SDL_KEYUP:
            keyPressed = "";
            break;
            */
        case SDL_MOUSEMOTION:
        case SDL_MOUSEBUTTONDOWN:
        case SDL_MOUSEBUTTONUP:
        case SDL_MOUSEWHEEL:
			logMsg("Mouse!");
            // processes mouse input
            if (processUnbufferedMouseInput() == false)
            {
                return false;
            }
            exit(0);
            break;
        case SDL_CONTROLLERAXISMOTION:
        case SDL_CONTROLLERBUTTONDOWN:
        case SDL_CONTROLLERBUTTONUP:
        case SDL_CONTROLLERDEVICEADDED:
        case SDL_CONTROLLERDEVICEREMOVED:
        case SDL_CONTROLLERDEVICEREMAPPED:
			logMsg("Controller!");
            // processes gamepad input
            if (processUnbufferedGamepadInput() == false)
            {
                return false;
            }
            exit(0);
           break;
        case SDL_QUIT:
            break;
        default:
            break;
    }

}-- 

Sent from my Android device with K-9 Mail. Please excuse my brevity.

Try changing your “if(SDL_PollEvent(…))” to "while(SDL_PollEvent(…))"
so that it checks all events and not just the first one.

Jonny DOn Friday, April 10, 2015, Mike McLean wrote:

Hello,

I have been unable to process any touch input events on my android
devices. Keyboard input on the other hand works just fine. I have debugged
it so far by putting a System.exit() statement in the onNativeTouch()
function in SDLActivity.java which causes the program to exit as soon as
the screen is touched. I then removed that statement and further debugged
by adding exit(0); to Java_org_libsdl_app_SDLActivity_onNativeTouch in
src/core/android/sdl_android.c which exited in the same fashion as the Java
code. So it appears that SDL is receiving touch events. However, when I
check with the following code I get nothing. Am I doing something wrong or
missing something obvious?

if (SDL_PollEvent(&inputEvent))
{
int numTouch = SDL_GetNumTouchDevices();
logMsg ("numTouch = " +Ogre::StringConverter::toString(numTouch));
//exit(0);

// Ogre::LogManager::getSingletonPtr()->logMessage(“Crash??”);

switch (inputEvent.type)
{
case SDL_WINDOWEVENT:
logMsg(“windowevent!”);
exit(0);
break;
case SDL_FINGERMOTION:
logMsg(“Motion!”);
exit(0);
// processes touch input
if (processUnbufferedTouchInput() == false)
{
return false;
}
break;
case SDL_FINGERDOWN:
logMsg(“Finger Down!”);
exit(0);
// processes touch input
if (processUnbufferedTouchInput() == false)
{
return false;
}
break;
case SDL_FINGERUP:
logMsg(“Finger Up!”);
exit(0);
// processes touch input
if (processUnbufferedTouchInput() == false)
{
return false;
}
break;
case SDL_MULTIGESTURE:
logMsg(“Multigesture!”);
exit(0);
// processes touch input
if (processUnbufferedTouchInput() == false)
{
return false;
}
break;

case SDL_TEXTINPUT:
keyPressed = “”;
if (processUnbufferedKeyInput(true) == false)
{
return false;
}

break;
/*
case SDL_KEYDOWN:
logMsg(“Keydown!”);
if (processUnbufferedKeyInput(false) == false)
{
return false;
}
break;

case SDL_KEYUP:
keyPressed = “”;
break;
*/
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEWHEEL:
logMsg(“Mouse!”);
// processes mouse input
if (processUnbufferedMouseInput() == false)
{
return false;
}
exit(0);
break;
case SDL_CONTROLLERAXISMOTION:
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
case SDL_CONTROLLERDEVICEREMAPPED:
logMsg(“Controller!”);
// processes gamepad input
if (processUnbufferedGamepadInput() == false)
{
return false;
}
exit(0);
break;
case SDL_QUIT:
break;
default:
break;
}

}

Sent from my Android device with K-9 Mail. Please excuse my brevity.

Thanks for the tip but it didn’t fix the problem. I have debugged further and found why I am not getting the touch input events. In the function Android_OnTouch in src/video/android/SDL_androidtouch.c it hits the following code and returns.

if (!Android_Window) {
return;
}

I am assuming this is related to the fact that I use OGRE for my graphics rendering engine and it initializes the display. I have tried using SDL_CreateWindowFrom() on the OGRE window but this has no effect. Is there another way that I can pass the window to SDL so that it doesn’t fail here?On April 10, 2015 7:39:49 AM MST, Jonathan Dearborn wrote:

Try changing your “if(SDL_PollEvent(…))” to
"while(SDL_PollEvent(…))"
so that it checks all events and not just the first one.

Jonny D

On Friday, April 10, 2015, Mike McLean <@Mike_McLean> wrote:

Hello,

I have been unable to process any touch input events on my android
devices. Keyboard input on the other hand works just fine. I have
debugged
it so far by putting a System.exit() statement in the onNativeTouch()
function in SDLActivity.java which causes the program to exit as soon
as
the screen is touched. I then removed that statement and further
debugged
by adding exit(0); to Java_org_libsdl_app_SDLActivity_onNativeTouch
in
src/core/android/sdl_android.c which exited in the same fashion as
the Java
code. So it appears that SDL is receiving touch events. However, when
I
check with the following code I get nothing. Am I doing something
wrong or
missing something obvious?

if (SDL_PollEvent(&inputEvent))
{
int numTouch = SDL_GetNumTouchDevices();
logMsg ("numTouch = " +Ogre::StringConverter::toString(numTouch));
//exit(0);

// Ogre::LogManager::getSingletonPtr()->logMessage(“Crash??”);

switch (inputEvent.type)
{
case SDL_WINDOWEVENT:
logMsg(“windowevent!”);
exit(0);
break;
case SDL_FINGERMOTION:
logMsg(“Motion!”);
exit(0);
// processes touch input
if (processUnbufferedTouchInput() == false)
{
return false;
}
break;
case SDL_FINGERDOWN:
logMsg(“Finger Down!”);
exit(0);
// processes touch input
if (processUnbufferedTouchInput() == false)
{
return false;
}
break;
case SDL_FINGERUP:
logMsg(“Finger Up!”);
exit(0);
// processes touch input
if (processUnbufferedTouchInput() == false)
{
return false;
}
break;
case SDL_MULTIGESTURE:
logMsg(“Multigesture!”);
exit(0);
// processes touch input
if (processUnbufferedTouchInput() == false)
{
return false;
}
break;

case SDL_TEXTINPUT:
keyPressed = “”;
if (processUnbufferedKeyInput(true) == false)
{
return false;
}

break;
/*
case SDL_KEYDOWN:
logMsg(“Keydown!”);
if (processUnbufferedKeyInput(false) == false)
{
return false;
}
break;

case SDL_KEYUP:
keyPressed = “”;
break;
*/
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEWHEEL:
logMsg(“Mouse!”);
// processes mouse input
if (processUnbufferedMouseInput() == false)
{
return false;
}
exit(0);
break;
case SDL_CONTROLLERAXISMOTION:
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
case SDL_CONTROLLERDEVICEREMAPPED:
logMsg(“Controller!”);
// processes gamepad input
if (processUnbufferedGamepadInput() == false)
{
return false;
}
exit(0);
break;
case SDL_QUIT:
break;
default:
break;
}

}

Sent from my Android device with K-9 Mail. Please excuse my brevity.



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


Sent from my Android device with K-9 Mail. Please excuse my brevity.

I have figured out the problem and come up with a solution. It appears that SDL does not currently implement SDL_CreateWindowFrom() on Android. So calling it instead of SDL_CreateWindow does nothing and Android_Window never gets set. I have implemented a basic SDL_CreateWindowFrom function for Android modeled after the ones for other platforms and now can receive touch input events. I will work up a patch later in case someone wants to include it in SDL.

MikeOn April 10, 2015 10:04:46 AM MST, Mike McLean <@Mike_McLean> wrote:

Thanks for the tip but it didn’t fix the problem. I have debugged
further and found why I am not getting the touch input events. In the
function Android_OnTouch in src/video/android/SDL_androidtouch.c it
hits the following code and returns.

if (!Android_Window) {
return;
}

I am assuming this is related to the fact that I use OGRE for my
graphics rendering engine and it initializes the display. I have tried
using SDL_CreateWindowFrom() on the OGRE window but this has no
effect. Is there another way that I can pass the window to SDL so that
it doesn’t fail here?

On April 10, 2015 7:39:49 AM MST, Jonathan Dearborn wrote:

Try changing your “if(SDL_PollEvent(…))” to
"while(SDL_PollEvent(…))"
so that it checks all events and not just the first one.

Jonny D

On Friday, April 10, 2015, Mike McLean <@Mike_McLean> wrote:

Hello,

I have been unable to process any touch input events on my android
devices. Keyboard input on the other hand works just fine. I have
debugged
it so far by putting a System.exit() statement in the
onNativeTouch()

function in SDLActivity.java which causes the program to exit as
soon
as

the screen is touched. I then removed that statement and further
debugged
by adding exit(0); to Java_org_libsdl_app_SDLActivity_onNativeTouch
in
src/core/android/sdl_android.c which exited in the same fashion as
the Java
code. So it appears that SDL is receiving touch events. However,
when
I

check with the following code I get nothing. Am I doing something
wrong or
missing something obvious?

if (SDL_PollEvent(&inputEvent))
{
int numTouch = SDL_GetNumTouchDevices();
logMsg ("numTouch = " +Ogre::StringConverter::toString(numTouch));
//exit(0);

// Ogre::LogManager::getSingletonPtr()->logMessage(“Crash??”);

switch (inputEvent.type)
{
case SDL_WINDOWEVENT:
logMsg(“windowevent!”);
exit(0);
break;
case SDL_FINGERMOTION:
logMsg(“Motion!”);
exit(0);
// processes touch input
if (processUnbufferedTouchInput() == false)
{
return false;
}
break;
case SDL_FINGERDOWN:
logMsg(“Finger Down!”);
exit(0);
// processes touch input
if (processUnbufferedTouchInput() == false)
{
return false;
}
break;
case SDL_FINGERUP:
logMsg(“Finger Up!”);
exit(0);
// processes touch input
if (processUnbufferedTouchInput() == false)
{
return false;
}
break;
case SDL_MULTIGESTURE:
logMsg(“Multigesture!”);
exit(0);
// processes touch input
if (processUnbufferedTouchInput() == false)
{
return false;
}
break;

case SDL_TEXTINPUT:
keyPressed = “”;
if (processUnbufferedKeyInput(true) == false)
{
return false;
}

break;
/*
case SDL_KEYDOWN:
logMsg(“Keydown!”);
if (processUnbufferedKeyInput(false) == false)
{
return false;
}
break;

case SDL_KEYUP:
keyPressed = “”;
break;
*/
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEWHEEL:
logMsg(“Mouse!”);
// processes mouse input
if (processUnbufferedMouseInput() == false)
{
return false;
}
exit(0);
break;
case SDL_CONTROLLERAXISMOTION:
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
case SDL_CONTROLLERDEVICEREMAPPED:
logMsg(“Controller!”);
// processes gamepad input
if (processUnbufferedGamepadInput() == false)
{
return false;
}
exit(0);
break;
case SDL_QUIT:
break;
default:
break;
}

}

Sent from my Android device with K-9 Mail. Please excuse my brevity.



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


Sent from my Android device with K-9 Mail. Please excuse my brevity.



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


Sent from my Android device with K-9 Mail. Please excuse my brevity.

Awesome job!

Jonny DOn Fri, Apr 10, 2015 at 5:14 PM, Mike McLean wrote:

I have figured out the problem and come up with a solution. It appears
that SDL does not currently implement SDL_CreateWindowFrom() on Android. So
calling it instead of SDL_CreateWindow does nothing and Android_Window
never gets set. I have implemented a basic SDL_CreateWindowFrom function
for Android modeled after the ones for other platforms and now can receive
touch input events. I will work up a patch later in case someone wants to
include it in SDL.

Mike

On April 10, 2015 10:04:46 AM MST, Mike McLean wrote:

Thanks for the tip but it didn’t fix the problem. I have debugged further
and found why I am not getting the touch input events. In the function
Android_OnTouch in src/video/android/SDL_androidtouch.c it hits the
following code and returns.

if (!Android_Window) {
return;
}

I am assuming this is related to the fact that I use OGRE for my graphics
rendering engine and it initializes the display. I have tried using
SDL_CreateWindowFrom() on the OGRE window but this has no effect. Is there
another way that I can pass the window to SDL so that it doesn’t fail here?

On April 10, 2015 7:39:49 AM MST, Jonathan Dearborn <@Jonathan_Dearborn> wrote:

Try changing your “if(SDL_PollEvent(…))” to
"while(SDL_PollEvent(…))" so that it checks all events and not just the
first one.

Jonny D

On Friday, April 10, 2015, Mike McLean wrote:

Hello,

I have been unable to process any touch input events on my android
devices. Keyboard input on the other hand works just fine. I have debugged
it so far by putting a System.exit() statement in the onNativeTouch()
function in SDLActivity.java which causes the program to exit as soon as
the screen is touched. I then removed that statement and further debugged
by adding exit(0); to Java_org_libsdl_app_SDLActivity_onNativeTouch in
src/core/android/sdl_android.c which exited in the same fashion as the Java
code. So it appears that SDL is receiving touch events. However, when I
check with the following code I get nothing. Am I doing something wrong or
missing something obvious?

if (SDL_PollEvent(&inputEvent))
{
int numTouch = SDL_GetNumTouchDevices();
logMsg ("numTouch = " +Ogre::StringConverter::toString(numTouch));
//exit(0);

// Ogre::LogManager::getSingletonPtr()->logMessage(“Crash??”);

switch (inputEvent.type)
{
case SDL_WINDOWEVENT:
logMsg(“windowevent!”);
exit(0);
break;
case SDL_FINGERMOTION:
logMsg(“Motion!”);
exit(0);
// processes touch input
if (processUnbufferedTouchInput() == false)
{
return false;
}
break;
case SDL_FINGERDOWN:
logMsg(“Finger Down!”);
exit(0);
// processes touch input
if (processUnbufferedTouchInput() == false)
{
return false;
}
break;
case SDL_FINGERUP:
logMsg(“Finger Up!”);
exit(0);
// processes touch input
if (processUnbufferedTouchInput() == false)
{
return false;
}
break;
case SDL_MULTIGESTURE:
logMsg(“Multigesture!”);
exit(0);
// processes touch input
if (processUnbufferedTouchInput() == false)
{
return false;
}
break;

case SDL_TEXTINPUT:
keyPressed = “”;
if (processUnbufferedKeyInput(true) == false)
{
return false;
}

break;
/*
case SDL_KEYDOWN:
logMsg(“Keydown!”);
if (processUnbufferedKeyInput(false) == false)
{
return false;
}
break;

case SDL_KEYUP:
keyPressed = “”;
break;
*/
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEWHEEL:
logMsg(“Mouse!”);
// processes mouse input
if (processUnbufferedMouseInput() == false)
{
return false;
}
exit(0);
break;
case SDL_CONTROLLERAXISMOTION:
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
case SDL_CONTROLLERDEVICEREMAPPED:
logMsg(“Controller!”);
// processes gamepad input
if (processUnbufferedGamepadInput() == false)
{
return false;
}
exit(0);
break;
case SDL_QUIT:
break;
default:
break;
}

}

Sent from my Android device with K-9 Mail. Please excuse my brevity.


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


Sent from my Android device with K-9 Mail. Please excuse my brevity.


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