added support for keyboard modifier keys

This commit is contained in:
Diego Waxemberg 2013-12-08 14:44:01 -05:00
parent 895c123b13
commit 87152e6403
4 changed files with 17 additions and 10 deletions

View File

@ -319,7 +319,7 @@ public class NvConnection {
}); });
} }
public void sendKeyboardInput(final short keyMap, final byte keyDirection) { public void sendKeyboardInput(final short keyMap, final byte keyDirection, final byte modifier) {
if (inputStream == null) if (inputStream == null)
return; return;
@ -327,7 +327,7 @@ public class NvConnection {
@Override @Override
public void run() { public void run() {
try { try {
inputStream.sendKeyboardInput(keyMap, keyDirection); inputStream.sendKeyboardInput(keyMap, keyDirection, modifier);
} catch (IOException e) { } catch (IOException e) {
listener.displayMessage(e.getMessage()); listener.displayMessage(e.getMessage());
NvConnection.this.stop(); NvConnection.this.stop();

View File

@ -10,13 +10,20 @@ public class KeyboardPacket extends InputPacket {
public static final byte KEY_DOWN = 0x03; public static final byte KEY_DOWN = 0x03;
public static final byte KEY_UP = 0x04; public static final byte KEY_UP = 0x04;
public static final byte MODIFIER_SHIFT = 0x01;
public static final byte MODIFIER_CTRL = 0x02;
public static final byte MODIFIER_ALT = 0x04;
private short keyCode; private short keyCode;
private byte keyDirection; private byte keyDirection;
private byte modifier;
public KeyboardPacket(short keyCode, byte keyDirection) { public KeyboardPacket(short keyCode, byte keyDirection, byte modifier) {
super(PACKET_TYPE); super(PACKET_TYPE);
this.keyCode = keyCode; this.keyCode = keyCode;
this.keyDirection = keyDirection; this.keyDirection = keyDirection;
this.modifier = modifier;
} }
public byte[] toWireHeader() public byte[] toWireHeader()
@ -37,7 +44,7 @@ public class KeyboardPacket extends InputPacket {
bb.putShort((short)0); bb.putShort((short)0);
bb.putShort((short)0); bb.putShort((short)0);
bb.putShort(keyCode); bb.putShort(keyCode);
bb.put((byte)0); bb.put(modifier);
bb.put((byte)0); bb.put((byte)0);
bb.put((byte)0); bb.put((byte)0);
byte[] packet = bb.array(); byte[] packet = bb.array();

View File

@ -10,11 +10,11 @@ public abstract class KeycodeTranslator {
this.conn = conn; this.conn = conn;
} }
public void sendKeyDown(short keyMap) { public void sendKeyDown(short keyMap, byte modifier) {
conn.sendKeyboardInput(keyMap, KeyboardPacket.KEY_DOWN); conn.sendKeyboardInput(keyMap, KeyboardPacket.KEY_DOWN, modifier);
} }
public void sendKeyUp(short keyMap) { public void sendKeyUp(short keyMap, byte modifier) {
conn.sendKeyboardInput(keyMap, KeyboardPacket.KEY_UP); conn.sendKeyboardInput(keyMap, KeyboardPacket.KEY_UP, modifier);
} }
} }

View File

@ -63,9 +63,9 @@ public class NvController {
out.flush(); out.flush();
} }
public void sendKeyboardInput(short keyMap, byte keyDirection) throws IOException public void sendKeyboardInput(short keyMap, byte keyDirection, byte modifier) throws IOException
{ {
out.write(new KeyboardPacket(keyMap, keyDirection).toWire()); out.write(new KeyboardPacket(keyMap, keyDirection, modifier).toWire());
out.flush(); out.flush();
} }
} }