mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-19 19:13:03 +00:00
added support for sending keyboard key presses
This commit is contained in:
parent
29909e07e8
commit
35476e2c28
@ -318,4 +318,21 @@ public class NvConnection {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void sendKeyboardInput(final short keyMap, final byte keyDirection) {
|
||||
if (inputStream == null)
|
||||
return;
|
||||
|
||||
threadPool.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
inputStream.sendKeyboardInput(keyMap, keyDirection);
|
||||
} catch (IOException e) {
|
||||
listener.displayMessage(e.getMessage());
|
||||
NvConnection.this.stop();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,50 @@
|
||||
package com.limelight.nvstream.input;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
public class KeyboardPacket extends InputPacket {
|
||||
private static final int PACKET_TYPE = 0x0A;
|
||||
private static final int PACKET_LENGTH = 14;
|
||||
|
||||
public static final byte KEY_DOWN = 0x03;
|
||||
public static final byte KEY_UP = 0x04;
|
||||
|
||||
private short keyCode;
|
||||
private byte keyDirection;
|
||||
|
||||
public KeyboardPacket(short keyCode, byte keyDirection) {
|
||||
super(PACKET_TYPE);
|
||||
this.keyCode = keyCode;
|
||||
this.keyDirection = keyDirection;
|
||||
}
|
||||
|
||||
public byte[] toWireHeader()
|
||||
{
|
||||
ByteBuffer bb = ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN);
|
||||
|
||||
bb.putInt(packetType);
|
||||
|
||||
return bb.array();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] toWire() {
|
||||
ByteBuffer bb = ByteBuffer.allocate(PACKET_LENGTH).order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
bb.put(toWireHeader());
|
||||
bb.put(keyDirection);
|
||||
bb.putShort((short)0);
|
||||
bb.putShort((short)0);
|
||||
bb.putShort(keyCode);
|
||||
bb.put((byte)0);
|
||||
bb.put((byte)0);
|
||||
bb.put((byte)0);
|
||||
byte[] packet = bb.array();
|
||||
for (int i = 0; i < packet.length; i++) {
|
||||
System.out.printf("%02x ", packet[i]);
|
||||
}
|
||||
System.out.println();
|
||||
return bb.array();
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.limelight.nvstream.input;
|
||||
|
||||
import com.limelight.nvstream.NvConnection;
|
||||
|
||||
public abstract class KeycodeTranslator {
|
||||
public abstract short translate(int keycode);
|
||||
protected NvConnection conn;
|
||||
|
||||
public KeycodeTranslator(NvConnection conn) {
|
||||
this.conn = conn;
|
||||
}
|
||||
|
||||
public void sendKeyDown(short keyMap) {
|
||||
conn.sendKeyboardInput(keyMap, KeyboardPacket.KEY_DOWN);
|
||||
}
|
||||
|
||||
public void sendKeyUp(short keyMap) {
|
||||
conn.sendKeyboardInput(keyMap, KeyboardPacket.KEY_UP);
|
||||
}
|
||||
}
|
@ -62,4 +62,11 @@ public class NvController {
|
||||
out.write(new MouseMovePacket(deltaX, deltaY).toWire());
|
||||
out.flush();
|
||||
}
|
||||
|
||||
public void sendKeyboardInput(short keyMap, byte keyDirection) throws IOException
|
||||
{
|
||||
System.out.println("sending keyboard packet");
|
||||
out.write(new KeyboardPacket(keyMap, keyDirection).toWire());
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user