added support for all 3 mouse buttons

This commit is contained in:
Diego Waxemberg 2013-12-08 16:25:41 -05:00
parent 87152e6403
commit da47b43ad3
3 changed files with 21 additions and 11 deletions

View File

@ -263,7 +263,7 @@ public class NvConnection {
}); });
} }
public void sendMouseButtonDown() public void sendMouseButtonDown(final byte mouseButton)
{ {
if (inputStream == null) if (inputStream == null)
return; return;
@ -272,7 +272,7 @@ public class NvConnection {
@Override @Override
public void run() { public void run() {
try { try {
inputStream.sendMouseButtonDown(); inputStream.sendMouseButtonDown(mouseButton);
} catch (IOException e) { } catch (IOException e) {
listener.connectionTerminated(e); listener.connectionTerminated(e);
} }
@ -280,7 +280,7 @@ public class NvConnection {
}); });
} }
public void sendMouseButtonUp() public void sendMouseButtonUp(final byte mouseButton)
{ {
if (inputStream == null) if (inputStream == null)
return; return;
@ -289,7 +289,7 @@ public class NvConnection {
@Override @Override
public void run() { public void run() {
try { try {
inputStream.sendMouseButtonUp(); inputStream.sendMouseButtonUp(mouseButton);
} catch (IOException e) { } catch (IOException e) {
listener.connectionTerminated(e); listener.connectionTerminated(e);
} }

View File

@ -6,6 +6,7 @@ import java.nio.ByteOrder;
public class MouseButtonPacket extends InputPacket { public class MouseButtonPacket extends InputPacket {
private byte buttonEventType; private byte buttonEventType;
private byte mouseButton;
public static final int PACKET_TYPE = 0x5; public static final int PACKET_TYPE = 0x5;
public static final int PAYLOAD_LENGTH = 5; public static final int PAYLOAD_LENGTH = 5;
@ -15,11 +16,20 @@ public class MouseButtonPacket extends InputPacket {
public static final byte PRESS_EVENT = 0x07; public static final byte PRESS_EVENT = 0x07;
public static final byte RELEASE_EVENT = 0x08; public static final byte RELEASE_EVENT = 0x08;
public MouseButtonPacket(boolean leftButtonDown) // left
public static final byte BUTTON_1 = 0x01;
// middle
public static final byte BUTTON_2 = 0x02;
// right
public static final byte BUTTON_3 = 0x03;
public MouseButtonPacket(boolean buttonDown, byte mouseButton)
{ {
super(PACKET_TYPE); super(PACKET_TYPE);
buttonEventType = leftButtonDown ? this.mouseButton = mouseButton;
buttonEventType = buttonDown ?
PRESS_EVENT : RELEASE_EVENT; PRESS_EVENT : RELEASE_EVENT;
} }
@ -29,7 +39,7 @@ public class MouseButtonPacket extends InputPacket {
bb.put(toWireHeader()); bb.put(toWireHeader());
bb.put(buttonEventType); bb.put(buttonEventType);
bb.putInt(1); // FIXME: button index? bb.putInt(mouseButton);
return bb.array(); return bb.array();
} }

View File

@ -45,15 +45,15 @@ public class NvController {
out.flush(); out.flush();
} }
public void sendMouseButtonDown() throws IOException public void sendMouseButtonDown(byte mouseButton) throws IOException
{ {
out.write(new MouseButtonPacket(true).toWire()); out.write(new MouseButtonPacket(true, mouseButton).toWire());
out.flush(); out.flush();
} }
public void sendMouseButtonUp() throws IOException public void sendMouseButtonUp(byte mouseButton) throws IOException
{ {
out.write(new MouseButtonPacket(false).toWire()); out.write(new MouseButtonPacket(false, mouseButton).toWire());
out.flush(); out.flush();
} }