0

i'm trying to differentiate between a joystick and a d-pad input. i always get the same Event source (16777232). it doesnt matter if i push the d-pad or the turn the joystick.

i'm using a ipega gamecontroller

my problem is:
First:
when I turn the left joystick to the right:
1. dispatchGenericMotionEvent(MotionEvent motionEvent) is triggered. and
a= 16777232(SOURCE_JOYSTICK)
2. It will forward to dispatchKeyEvent(KeyEvent event)

Second:
When I turn the right joystick to the right:
1. ispatchGenericMotionEvent(MotionEvent motionEvent) is triggered. and
a= 16777232(SOURCE_JOYSTICK)
2. It does forward to dispatchKeyEvent(KeyEvent event)

Third:
When I push the left/right/up/down d-pad button:
1.ispatchGenericMotionEvent(MotionEvent motionEvent) is triggered. and
a= 16777232(SOURCE_JOYSTICK)
2. It will forward to dispatchKeyEvent(KeyEvent event)

@Override
public boolean dispatchGenericMotionEvent(MotionEvent motionEvent)
{
    int a=motionEvent.getSource();

    return super.dispatchGenericMotionEvent(motionEvent);
}

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int a=motionEvent.getSource();

    return super.dispatchKeyEvent(event);
}
Pau
  • 1
  • 3
  • 1
    I've added an [answer](https://stackoverflow.com/a/58510631/11029770) to another question that should hopefully answer this as well! – ConcernedHobbit Oct 22 '19 at 19:00

1 Answers1

0

I'm not sure you are having the same problem I once had (I only tried a DS4 on a specific cell phone)

What I came across is that using the dispatchKeyEvent method the controller was mixing up(giving me the same response) for the left stick and the directional pad, and, if I remember correctly, mixing the left and right stick commands.

If you log everytime a stick is moved or a button is pressed, you'll see that some actions call both onGenericMotionEvent and dispatchKeyEvent, but with different events.

What I had to do was to separate the actions of both sticks with the onGenericMotionEvent method(which will also give you intensity from 0.0 to 1.0) and the dispatchKeyEvent method would keep firing KeyEvents.