mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-06-17 06:11:36 +00:00
add in Ctrl-alt-shift-Q to quit, and do better edge detection
This commit is contained in:
@@ -31,9 +31,13 @@ public class StreamFrame extends JFrame {
|
|||||||
private MouseHandler mouse;
|
private MouseHandler mouse;
|
||||||
private JProgressBar spinner;
|
private JProgressBar spinner;
|
||||||
private JLabel spinnerLabel;
|
private JLabel spinnerLabel;
|
||||||
|
|
||||||
|
private NvConnection conn;
|
||||||
|
|
||||||
public void build(NvConnection conn, boolean fullscreen) {
|
public void build(NvConnection conn, boolean fullscreen) {
|
||||||
keyboard = new KeyboardHandler(conn);
|
this.conn = conn;
|
||||||
|
|
||||||
|
keyboard = new KeyboardHandler(conn, this);
|
||||||
mouse = new MouseHandler(conn, this);
|
mouse = new MouseHandler(conn, this);
|
||||||
|
|
||||||
this.addKeyListener(keyboard);
|
this.addKeyListener(keyboard);
|
||||||
@@ -123,4 +127,9 @@ public class StreamFrame extends JFrame {
|
|||||||
spinnerLabel.setVisible(false);
|
spinnerLabel.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
dispose();
|
||||||
|
conn.stop();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,18 @@ package com.limelight.input;
|
|||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.KeyListener;
|
import java.awt.event.KeyListener;
|
||||||
|
|
||||||
|
import com.limelight.gui.StreamFrame;
|
||||||
import com.limelight.nvstream.NvConnection;
|
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;
|
||||||
|
|
||||||
public KeyboardHandler(NvConnection conn) {
|
public KeyboardHandler(NvConnection conn, StreamFrame parent) {
|
||||||
translator = new KeyboardTranslator(conn);
|
translator = new KeyboardTranslator(conn);
|
||||||
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -30,6 +33,15 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0 &&
|
||||||
|
(modifiers & KeyEvent.ALT_DOWN_MASK) != 0 &&
|
||||||
|
(modifiers & KeyEvent.CTRL_DOWN_MASK) != 0 &&
|
||||||
|
event.getKeyCode() == KeyEvent.VK_Q) {
|
||||||
|
System.out.println("quitting");
|
||||||
|
parent.close();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
translator.sendKeyDown(keyMap, modifier);
|
translator.sendKeyDown(keyMap, modifier);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ public class MouseHandler implements MouseListener, MouseMotionListener {
|
|||||||
private int lastX = 0;
|
private int lastX = 0;
|
||||||
private int lastY = 0;
|
private int lastY = 0;
|
||||||
|
|
||||||
|
|
||||||
public MouseHandler(NvConnection conn, JFrame parent) {
|
public MouseHandler(NvConnection conn, JFrame parent) {
|
||||||
this.conn = conn;
|
this.conn = conn;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
@@ -44,9 +43,9 @@ public class MouseHandler implements MouseListener, MouseMotionListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseExited(MouseEvent e) {
|
public void mouseExited(MouseEvent e) {
|
||||||
robot.mouseMove(size.width / 2, size.height / 2);
|
parent.getSize(size);
|
||||||
lastX = size.width / 2;
|
moveMouse((int)parent.getLocation().getX() + (size.width/2),
|
||||||
lastY = size.height / 2;
|
(int)parent.getLocation().getY() + (size.height/2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -106,15 +105,24 @@ public class MouseHandler implements MouseListener, MouseMotionListener {
|
|||||||
|
|
||||||
parent.getSize(size);
|
parent.getSize(size);
|
||||||
|
|
||||||
if (x < size.width / 2 - 500 || x > size.width / 2 + 500) {
|
int leftEdge = (int) parent.getLocation().getX();
|
||||||
robot.mouseMove(size.width / 2, y);
|
int rightEdge = leftEdge + size.width;
|
||||||
lastX = size.width / 2;
|
int upperEdge = (int) parent.getLocation().getY();
|
||||||
|
int lowerEdge = upperEdge + size.height;
|
||||||
|
|
||||||
|
if (x < leftEdge + 100 || x > rightEdge - 100) {
|
||||||
|
moveMouse((leftEdge+rightEdge)/2, (upperEdge+lowerEdge)/2);
|
||||||
}
|
}
|
||||||
if (y < size.height / 2 - 300 || y > size.height / 2 + 300) {
|
if (y < upperEdge + 100 || y > lowerEdge - 100) {
|
||||||
robot.mouseMove(x, size.height / 2);
|
moveMouse((leftEdge+rightEdge)/2, (upperEdge+lowerEdge)/2);
|
||||||
lastY = size.height / 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void moveMouse(int x, int y) {
|
||||||
|
robot.mouseMove(x, y);
|
||||||
|
lastX = x;
|
||||||
|
lastY = y;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user