Add support for secondary and tertiary mouse buttons

This commit is contained in:
Cameron Gutman 2014-03-25 20:16:23 -04:00
parent bafb9e6230
commit 0d42beca93

View File

@ -40,6 +40,7 @@ public class Game extends Activity implements OnGenericMotionListener, OnTouchLi
private short leftStickY = 0x0000; private short leftStickY = 0x0000;
private int lastMouseX = Integer.MIN_VALUE; private int lastMouseX = Integer.MIN_VALUE;
private int lastMouseY = Integer.MIN_VALUE; private int lastMouseY = Integer.MIN_VALUE;
private int lastButtonState = 0;
private int lastTouchX = 0; private int lastTouchX = 0;
private int lastTouchY = 0; private int lastTouchY = 0;
private boolean hasMoved = false; private boolean hasMoved = false;
@ -363,17 +364,36 @@ public class Game extends Activity implements OnGenericMotionListener, OnTouchLi
// This case is for mice // This case is for mice
else if (event.getSource() == InputDevice.SOURCE_MOUSE) else if (event.getSource() == InputDevice.SOURCE_MOUSE)
{ {
switch (event.getActionMasked()) int changedButtons = event.getButtonState() ^ lastButtonState;
{
case MotionEvent.ACTION_DOWN: if ((changedButtons & MotionEvent.BUTTON_PRIMARY) != 0) {
conn.sendMouseButtonDown((byte) 0x01); if ((event.getButtonState() & MotionEvent.BUTTON_PRIMARY) != 0) {
break; conn.sendMouseButtonDown((byte) 0x01);
case MotionEvent.ACTION_UP: }
conn.sendMouseButtonUp((byte) 0x01); else {
break; conn.sendMouseButtonUp((byte) 0x01);
default: }
return super.onTouchEvent(event);
} }
if ((changedButtons & MotionEvent.BUTTON_SECONDARY) != 0) {
if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) {
conn.sendMouseButtonDown((byte) 0x03);
}
else {
conn.sendMouseButtonUp((byte) 0x03);
}
}
if ((changedButtons & MotionEvent.BUTTON_TERTIARY) != 0) {
if ((event.getButtonState() & MotionEvent.BUTTON_TERTIARY) != 0) {
conn.sendMouseButtonDown((byte) 0x02);
}
else {
conn.sendMouseButtonUp((byte) 0x02);
}
}
lastButtonState = event.getButtonState();
} }
else else
{ {