mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-06-16 13:51:15 +00:00
holding CTRL + ALT + SHIFT will now release the mouse. Also fixed mouse re-centering issue (i believe cannot test for sure on my system)
This commit is contained in:
@@ -26,23 +26,33 @@ import com.limelight.nvstream.NvConnectionListener.Stage;
|
|||||||
|
|
||||||
public class StreamFrame extends JFrame {
|
public class StreamFrame extends JFrame {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private int centerX;
|
private int centerX;
|
||||||
private int centerY;
|
private int centerY;
|
||||||
private KeyboardHandler keyboard;
|
private KeyboardHandler keyboard;
|
||||||
private MouseHandler mouse;
|
private MouseHandler mouse;
|
||||||
private JProgressBar spinner;
|
private JProgressBar spinner;
|
||||||
private JLabel spinnerLabel;
|
private JLabel spinnerLabel;
|
||||||
|
private Cursor noCursor;
|
||||||
private NvConnection conn;
|
private NvConnection conn;
|
||||||
|
|
||||||
public StreamFrame() {
|
public StreamFrame() {
|
||||||
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
|
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
|
||||||
this.setSize(1280,720);
|
this.setSize(1280,720);
|
||||||
centerX = dim.width/2-this.getSize().width/2;
|
centerX = dim.width/2-this.getSize().width/2;
|
||||||
centerY = dim.height/2-this.getSize().height/2;
|
centerY = dim.height/2-this.getSize().height/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void freeMouse() {
|
||||||
|
mouse.free();
|
||||||
|
showCursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void captureMouse() {
|
||||||
|
mouse.capture();
|
||||||
|
hideCursor();
|
||||||
|
}
|
||||||
|
|
||||||
public void build(NvConnection conn, boolean fullscreen) {
|
public void build(NvConnection conn, boolean fullscreen) {
|
||||||
this.conn = conn;
|
this.conn = conn;
|
||||||
|
|
||||||
@@ -59,11 +69,11 @@ public class StreamFrame extends JFrame {
|
|||||||
this.setLocation(centerX, 0);
|
this.setLocation(centerX, 0);
|
||||||
|
|
||||||
this.setBackground(Color.BLACK);
|
this.setBackground(Color.BLACK);
|
||||||
|
|
||||||
if (fullscreen) {
|
if (fullscreen) {
|
||||||
makeFullScreen();
|
makeFullScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
hideCursor();
|
hideCursor();
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
}
|
}
|
||||||
@@ -84,59 +94,66 @@ public class StreamFrame extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void hideCursor() {
|
private void hideCursor() {
|
||||||
// Transparent 16 x 16 pixel cursor image.
|
if (noCursor == null) {
|
||||||
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
// Transparent 16 x 16 pixel cursor image.
|
||||||
|
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||||
// Create a new blank cursor.
|
|
||||||
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
|
|
||||||
cursorImg, new Point(0, 0), "blank cursor");
|
|
||||||
|
|
||||||
|
// Create a new blank cursor.
|
||||||
|
noCursor = Toolkit.getDefaultToolkit().createCustomCursor(
|
||||||
|
cursorImg, new Point(0, 0), "blank cursor");
|
||||||
|
}
|
||||||
// Set the blank cursor to the JFrame.
|
// Set the blank cursor to the JFrame.
|
||||||
this.getContentPane().setCursor(blankCursor);
|
this.setCursor(noCursor);
|
||||||
|
this.getContentPane().setCursor(noCursor);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showCursor() {
|
||||||
|
this.setCursor(Cursor.getDefaultCursor());
|
||||||
|
this.getContentPane().setCursor(Cursor.getDefaultCursor());
|
||||||
|
}
|
||||||
|
|
||||||
public void showSpinner(Stage stage) {
|
public void showSpinner(Stage stage) {
|
||||||
|
|
||||||
if (spinner == null) {
|
if (spinner == null) {
|
||||||
Container c = this.getContentPane();
|
Container c = this.getContentPane();
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
spinner = new JProgressBar();
|
spinner = new JProgressBar();
|
||||||
spinner.setIndeterminate(true);
|
spinner.setIndeterminate(true);
|
||||||
spinner.setMaximumSize(new Dimension(150, 30));
|
spinner.setMaximumSize(new Dimension(150, 30));
|
||||||
|
|
||||||
spinnerLabel = new JLabel();
|
spinnerLabel = new JLabel();
|
||||||
spinnerLabel.setForeground(Color.white);
|
spinnerLabel.setForeground(Color.white);
|
||||||
|
|
||||||
Box spinBox = Box.createHorizontalBox();
|
Box spinBox = Box.createHorizontalBox();
|
||||||
spinBox.add(Box.createHorizontalGlue());
|
spinBox.add(Box.createHorizontalGlue());
|
||||||
spinBox.add(spinner);
|
spinBox.add(spinner);
|
||||||
spinBox.add(Box.createHorizontalGlue());
|
spinBox.add(Box.createHorizontalGlue());
|
||||||
|
|
||||||
Box lblBox = Box.createHorizontalBox();
|
Box lblBox = Box.createHorizontalBox();
|
||||||
lblBox.add(Box.createHorizontalGlue());
|
lblBox.add(Box.createHorizontalGlue());
|
||||||
lblBox.add(spinnerLabel);
|
lblBox.add(spinnerLabel);
|
||||||
lblBox.add(Box.createHorizontalGlue());
|
lblBox.add(Box.createHorizontalGlue());
|
||||||
|
|
||||||
panel.add(Box.createVerticalGlue());
|
panel.add(Box.createVerticalGlue());
|
||||||
panel.add(spinBox);
|
panel.add(spinBox);
|
||||||
panel.add(Box.createVerticalStrut(10));
|
panel.add(Box.createVerticalStrut(10));
|
||||||
panel.add(lblBox);
|
panel.add(lblBox);
|
||||||
panel.add(Box.createVerticalGlue());
|
panel.add(Box.createVerticalGlue());
|
||||||
|
|
||||||
c.setLayout(new BorderLayout());
|
c.setLayout(new BorderLayout());
|
||||||
c.add(panel, "Center");
|
c.add(panel, "Center");
|
||||||
}
|
}
|
||||||
spinnerLabel.setText("Starting " + stage.getName() + "...");
|
spinnerLabel.setText("Starting " + stage.getName() + "...");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideSpinner() {
|
public void hideSpinner() {
|
||||||
spinner.setVisible(false);
|
spinner.setVisible(false);
|
||||||
spinnerLabel.setVisible(false);
|
spinnerLabel.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
dispose();
|
dispose();
|
||||||
conn.stop();
|
conn.stop();
|
||||||
|
|||||||
@@ -8,21 +8,21 @@ import com.limelight.nvstream.NvConnection;
|
|||||||
import com.limelight.nvstream.input.KeyboardPacket;
|
import com.limelight.nvstream.input.KeyboardPacket;
|
||||||
|
|
||||||
public class KeyboardHandler implements KeyListener {
|
public class KeyboardHandler implements KeyListener {
|
||||||
|
|
||||||
private static KeyboardTranslator translator;
|
private static KeyboardTranslator translator;
|
||||||
private StreamFrame parent;
|
private StreamFrame parent;
|
||||||
|
|
||||||
public KeyboardHandler(NvConnection conn, StreamFrame parent) {
|
public KeyboardHandler(NvConnection conn, StreamFrame parent) {
|
||||||
translator = new KeyboardTranslator(conn);
|
translator = new KeyboardTranslator(conn);
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent event) {
|
public void keyPressed(KeyEvent event) {
|
||||||
short keyMap = translator.translate(event.getKeyCode());
|
short keyMap = translator.translate(event.getKeyCode());
|
||||||
|
|
||||||
byte modifier = 0x0;
|
byte modifier = 0x0;
|
||||||
|
|
||||||
int modifiers = event.getModifiersEx();
|
int modifiers = event.getModifiersEx();
|
||||||
if ((modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0) {
|
if ((modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0) {
|
||||||
modifier |= KeyboardPacket.MODIFIER_SHIFT;
|
modifier |= KeyboardPacket.MODIFIER_SHIFT;
|
||||||
@@ -35,23 +35,37 @@ public class KeyboardHandler implements KeyListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0 &&
|
if ((modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0 &&
|
||||||
(modifiers & KeyEvent.ALT_DOWN_MASK) != 0 &&
|
(modifiers & KeyEvent.ALT_DOWN_MASK) != 0 &&
|
||||||
(modifiers & KeyEvent.CTRL_DOWN_MASK) != 0 &&
|
(modifiers & KeyEvent.CTRL_DOWN_MASK) != 0 &&
|
||||||
event.getKeyCode() == KeyEvent.VK_Q) {
|
event.getKeyCode() == KeyEvent.VK_Q) {
|
||||||
System.out.println("quitting");
|
System.out.println("quitting");
|
||||||
parent.close();
|
parent.close();
|
||||||
|
} else if (
|
||||||
|
(modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0 &&
|
||||||
|
(modifiers & KeyEvent.ALT_DOWN_MASK) != 0 &&
|
||||||
|
(modifiers & KeyEvent.CTRL_DOWN_MASK) != 0) {
|
||||||
|
parent.freeMouse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
translator.sendKeyDown(keyMap, modifier);
|
translator.sendKeyDown(keyMap, modifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent event) {
|
public void keyReleased(KeyEvent event) {
|
||||||
short keyMap = translator.translate(event.getKeyCode());
|
|
||||||
|
|
||||||
byte modifier = 0x0;
|
|
||||||
|
|
||||||
int modifiers = event.getModifiersEx();
|
int modifiers = event.getModifiersEx();
|
||||||
|
|
||||||
|
if ((modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0 ||
|
||||||
|
(modifiers & KeyEvent.ALT_DOWN_MASK) != 0 ||
|
||||||
|
(modifiers & KeyEvent.CTRL_DOWN_MASK) != 0) {
|
||||||
|
parent.captureMouse();
|
||||||
|
}
|
||||||
|
|
||||||
|
short keyMap = translator.translate(event.getKeyCode());
|
||||||
|
|
||||||
|
byte modifier = 0x0;
|
||||||
|
|
||||||
if ((modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0) {
|
if ((modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0) {
|
||||||
modifier |= KeyboardPacket.MODIFIER_SHIFT;
|
modifier |= KeyboardPacket.MODIFIER_SHIFT;
|
||||||
}
|
}
|
||||||
@@ -61,7 +75,7 @@ public class KeyboardHandler implements KeyListener {
|
|||||||
if ((modifiers & KeyEvent.ALT_DOWN_MASK) != 0) {
|
if ((modifiers & KeyEvent.ALT_DOWN_MASK) != 0) {
|
||||||
modifier |= KeyboardPacket.MODIFIER_ALT;
|
modifier |= KeyboardPacket.MODIFIER_ALT;
|
||||||
}
|
}
|
||||||
|
|
||||||
translator.sendKeyUp(keyMap, modifier);
|
translator.sendKeyUp(keyMap, modifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ public class MouseHandler implements MouseListener, MouseMotionListener {
|
|||||||
private JFrame parent;
|
private JFrame parent;
|
||||||
private int lastX = 0;
|
private int lastX = 0;
|
||||||
private int lastY = 0;
|
private int lastY = 0;
|
||||||
|
private boolean captureMouse = true;
|
||||||
|
|
||||||
public MouseHandler(NvConnection conn, JFrame parent) {
|
public MouseHandler(NvConnection conn, JFrame parent) {
|
||||||
this.conn = conn;
|
this.conn = conn;
|
||||||
@@ -33,6 +34,16 @@ public class MouseHandler implements MouseListener, MouseMotionListener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void free() {
|
||||||
|
captureMouse = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void capture() {
|
||||||
|
moveMouse((int)parent.getLocationOnScreen().getX() + (size.width/2),
|
||||||
|
(int)parent.getLocationOnScreen().getY() + (size.height/2));
|
||||||
|
captureMouse = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
}
|
}
|
||||||
@@ -43,82 +54,91 @@ public class MouseHandler implements MouseListener, MouseMotionListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseExited(MouseEvent e) {
|
public void mouseExited(MouseEvent e) {
|
||||||
parent.getSize(size);
|
if (captureMouse) {
|
||||||
moveMouse((int)parent.getLocation().getX() + (size.width/2),
|
parent.getSize(size);
|
||||||
(int)parent.getLocation().getY() + (size.height/2));
|
moveMouse((int)parent.getLocationOnScreen().getX() + (size.width/2),
|
||||||
|
(int)parent.getLocationOnScreen().getY() + (size.height/2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
byte mouseButton = 0x0;
|
if (captureMouse) {
|
||||||
|
byte mouseButton = 0x0;
|
||||||
if (SwingUtilities.isLeftMouseButton(e)) {
|
|
||||||
mouseButton = MouseButtonPacket.BUTTON_1;
|
if (SwingUtilities.isLeftMouseButton(e)) {
|
||||||
}
|
mouseButton = MouseButtonPacket.BUTTON_1;
|
||||||
|
}
|
||||||
if (SwingUtilities.isMiddleMouseButton(e)) {
|
|
||||||
mouseButton = MouseButtonPacket.BUTTON_2;
|
if (SwingUtilities.isMiddleMouseButton(e)) {
|
||||||
}
|
mouseButton = MouseButtonPacket.BUTTON_2;
|
||||||
|
}
|
||||||
if (SwingUtilities.isRightMouseButton(e)) {
|
|
||||||
mouseButton = MouseButtonPacket.BUTTON_3;
|
if (SwingUtilities.isRightMouseButton(e)) {
|
||||||
}
|
mouseButton = MouseButtonPacket.BUTTON_3;
|
||||||
|
}
|
||||||
if (mouseButton > 0) {
|
|
||||||
conn.sendMouseButtonDown(mouseButton);
|
if (mouseButton > 0) {
|
||||||
|
conn.sendMouseButtonDown(mouseButton);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
byte mouseButton = 0x0;
|
if (captureMouse) {
|
||||||
|
byte mouseButton = 0x0;
|
||||||
if (SwingUtilities.isLeftMouseButton(e)) {
|
|
||||||
mouseButton = MouseButtonPacket.BUTTON_1;
|
if (SwingUtilities.isLeftMouseButton(e)) {
|
||||||
}
|
mouseButton = MouseButtonPacket.BUTTON_1;
|
||||||
|
}
|
||||||
if (SwingUtilities.isMiddleMouseButton(e)) {
|
|
||||||
mouseButton = MouseButtonPacket.BUTTON_2;
|
if (SwingUtilities.isMiddleMouseButton(e)) {
|
||||||
}
|
mouseButton = MouseButtonPacket.BUTTON_2;
|
||||||
|
}
|
||||||
if (SwingUtilities.isRightMouseButton(e)) {
|
|
||||||
mouseButton = MouseButtonPacket.BUTTON_3;
|
if (SwingUtilities.isRightMouseButton(e)) {
|
||||||
}
|
mouseButton = MouseButtonPacket.BUTTON_3;
|
||||||
|
}
|
||||||
if (mouseButton > 0) {
|
|
||||||
conn.sendMouseButtonUp(mouseButton);
|
if (mouseButton > 0) {
|
||||||
|
conn.sendMouseButtonUp(mouseButton);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseDragged(MouseEvent e) {
|
public void mouseDragged(MouseEvent e) {
|
||||||
mouseMoved(e);
|
if (captureMouse) {
|
||||||
|
mouseMoved(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved(MouseEvent e) {
|
public void mouseMoved(MouseEvent e) {
|
||||||
int x = e.getX();
|
if (captureMouse) {
|
||||||
int y = e.getY();
|
int x = e.getX();
|
||||||
conn.sendMouseMove((short)(x - lastX), (short)(y - lastY));
|
int y = e.getY();
|
||||||
lastX = x;
|
conn.sendMouseMove((short)(x - lastX), (short)(y - lastY));
|
||||||
lastY = y;
|
lastX = x;
|
||||||
|
lastY = y;
|
||||||
parent.getSize(size);
|
|
||||||
|
|
||||||
int leftEdge = (int) parent.getLocation().getX();
|
parent.getSize(size);
|
||||||
int rightEdge = leftEdge + size.width;
|
|
||||||
int upperEdge = (int) parent.getLocation().getY();
|
|
||||||
int lowerEdge = upperEdge + size.height;
|
|
||||||
|
|
||||||
if (x < leftEdge + 100 || x > rightEdge - 100) {
|
int leftEdge = (int) parent.getLocationOnScreen().getX();
|
||||||
moveMouse((leftEdge+rightEdge)/2, (upperEdge+lowerEdge)/2);
|
int rightEdge = leftEdge + size.width;
|
||||||
|
int upperEdge = (int) parent.getLocationOnScreen().getY();
|
||||||
|
int lowerEdge = upperEdge + size.height;
|
||||||
|
|
||||||
|
if (x < leftEdge + 100 || x > rightEdge - 100) {
|
||||||
|
moveMouse((leftEdge+rightEdge)/2, (upperEdge+lowerEdge)/2);
|
||||||
|
}
|
||||||
|
if (y < upperEdge + 100 || y > lowerEdge - 100) {
|
||||||
|
moveMouse((leftEdge+rightEdge)/2, (upperEdge+lowerEdge)/2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (y < upperEdge + 100 || y > lowerEdge - 100) {
|
|
||||||
moveMouse((leftEdge+rightEdge)/2, (upperEdge+lowerEdge)/2);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void moveMouse(int x, int y) {
|
private void moveMouse(int x, int y) {
|
||||||
robot.mouseMove(x, y);
|
robot.mouseMove(x, y);
|
||||||
lastX = x;
|
lastX = x;
|
||||||
|
|||||||
Reference in New Issue
Block a user