Only bind to keyboards and mice that aren't gamepads

This commit is contained in:
Cameron Gutman 2014-09-06 16:25:09 -07:00
parent 09e8e8e6b3
commit 828f4877b6
3 changed files with 29 additions and 6 deletions

View File

@ -24,6 +24,10 @@ public class EvdevEvent {
public static final short BTN_FORWARD = 0x115; public static final short BTN_FORWARD = 0x115;
public static final short BTN_BACK = 0x116; public static final short BTN_BACK = 0x116;
public static final short BTN_TASK = 0x117; public static final short BTN_TASK = 0x117;
public static final short BTN_GAMEPAD = 0x130;
/* Keys */
public static final short KEY_Q = 16;
public short type; public short type;
public short code; public short code;

View File

@ -26,9 +26,10 @@ public class EvdevHandler {
} }
try { try {
// Check if it's a mouse // Check if it's a mouse or keyboard, but not a gamepad
if (!EvdevReader.isMouse(fd)) { if ((!EvdevReader.isMouse(fd) && !EvdevReader.isAlphaKeyboard(fd)) ||
// We only handle mice EvdevReader.isGamepad(fd)) {
// We only handle keyboards and mice
return; return;
} }
@ -38,7 +39,7 @@ public class EvdevHandler {
return; return;
} }
LimeLog.info("Grabbed device for raw mouse input: "+absolutePath); LimeLog.info("Grabbed device for raw keyboard/mouse input: "+absolutePath);
ByteBuffer buffer = ByteBuffer.allocate(EvdevEvent.EVDEV_MAX_EVENT_SIZE).order(ByteOrder.nativeOrder()); ByteBuffer buffer = ByteBuffer.allocate(EvdevEvent.EVDEV_MAX_EVENT_SIZE).order(ByteOrder.nativeOrder());

View File

@ -43,8 +43,26 @@ public class EvdevReader {
public static native boolean grab(int fd); public static native boolean grab(int fd);
public static native boolean ungrab(int fd); public static native boolean ungrab(int fd);
// Returns true if the device is a mouse // Used for checking device capabilities
public static native boolean isMouse(int fd); public static native boolean hasRelAxis(int fd, short axis);
public static native boolean hasAbsAxis(int fd, short axis);
public static native boolean hasKey(int fd, short key);
public static boolean isMouse(int fd) {
// This is the same check that Android does in EventHub.cpp
return hasRelAxis(fd, EvdevEvent.REL_X) &&
hasRelAxis(fd, EvdevEvent.REL_Y) &&
hasKey(fd, EvdevEvent.BTN_LEFT);
}
public static boolean isAlphaKeyboard(int fd) {
// This is the same check that Android does in EventHub.cpp
return hasKey(fd, EvdevEvent.KEY_Q);
}
public static boolean isGamepad(int fd) {
return hasKey(fd, EvdevEvent.BTN_GAMEPAD);
}
// Returns the bytes read or -1 on error // Returns the bytes read or -1 on error
private static native int read(int fd, byte[] buffer); private static native int read(int fd, byte[] buffer);