Add vertical mouse scrolling support

This commit is contained in:
Cameron Gutman 2014-09-03 22:53:40 -07:00
parent ef1429a639
commit cde8ec8262
5 changed files with 28 additions and 3 deletions

Binary file not shown.

View File

@ -504,8 +504,18 @@ public class Game extends Activity implements SurfaceHolder.Callback,
}
else if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0)
{
// Send a mouse move update (if neccessary)
updateMousePosition((int)event.getX(), (int)event.getY());
switch (event.getActionMasked())
{
case MotionEvent.ACTION_HOVER_MOVE:
// Send a mouse move update (if neccessary)
updateMousePosition((int)event.getX(), (int)event.getY());
break;
case MotionEvent.ACTION_SCROLL:
// Send the vertical scroll packet
byte vScrollClicks = (byte) event.getAxisValue(MotionEvent.AXIS_VSCROLL);
conn.sendMouseScroll(vScrollClicks);
break;
}
return true;
}
@ -680,4 +690,9 @@ public class Game extends Activity implements SurfaceHolder.Callback,
conn.sendMouseButtonUp(buttonIndex);
}
}
@Override
public void mouseScroll(byte amount) {
conn.sendMouseScroll(amount);
}
}

View File

@ -12,6 +12,7 @@ public class EvdevEvent {
/* Relative axes */
public static final short REL_X = 0x00;
public static final short REL_Y = 0x01;
public static final short REL_WHEEL = 0x08;
/* Buttons */
public static final short BTN_LEFT = 0x110;

View File

@ -45,6 +45,7 @@ public class EvdevHandler {
try {
int deltaX = 0;
int deltaY = 0;
byte deltaScroll = 0;
while (!isInterrupted() && !shutdown) {
EvdevEvent event = EvdevReader.read(fd, buffer);
@ -59,6 +60,10 @@ public class EvdevHandler {
listener.mouseMove(deltaX, deltaY);
deltaX = deltaY = 0;
}
if (deltaScroll != 0) {
listener.mouseScroll(deltaScroll);
deltaScroll = 0;
}
break;
case EvdevEvent.EV_REL:
@ -70,6 +75,9 @@ public class EvdevHandler {
case EvdevEvent.REL_Y:
deltaY = event.value;
break;
case EvdevEvent.REL_WHEEL:
deltaScroll = (byte) event.value;
break;
}
break;

View File

@ -7,4 +7,5 @@ public interface EvdevListener {
public void mouseMove(int deltaX, int deltaY);
public void mouseButtonEvent(int buttonId, boolean down);
public void mouseScroll(byte amount);
}