mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-02-16 10:30:47 +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 JProgressBar spinner;
|
||||
private JLabel spinnerLabel;
|
||||
|
||||
private NvConnection conn;
|
||||
|
||||
public void build(NvConnection conn, boolean fullscreen) {
|
||||
keyboard = new KeyboardHandler(conn);
|
||||
this.conn = conn;
|
||||
|
||||
keyboard = new KeyboardHandler(conn, this);
|
||||
mouse = new MouseHandler(conn, this);
|
||||
|
||||
this.addKeyListener(keyboard);
|
||||
@@ -123,4 +127,9 @@ public class StreamFrame extends JFrame {
|
||||
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.KeyListener;
|
||||
|
||||
import com.limelight.gui.StreamFrame;
|
||||
import com.limelight.nvstream.NvConnection;
|
||||
import com.limelight.nvstream.input.KeyboardPacket;
|
||||
|
||||
public class KeyboardHandler implements KeyListener {
|
||||
|
||||
private static KeyboardTranslator translator;
|
||||
private StreamFrame parent;
|
||||
|
||||
public KeyboardHandler(NvConnection conn) {
|
||||
public KeyboardHandler(NvConnection conn, StreamFrame parent) {
|
||||
translator = new KeyboardTranslator(conn);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -30,6 +33,15 @@ public class KeyboardHandler implements KeyListener {
|
||||
if ((modifiers & KeyEvent.ALT_DOWN_MASK) != 0) {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ public class MouseHandler implements MouseListener, MouseMotionListener {
|
||||
private int lastX = 0;
|
||||
private int lastY = 0;
|
||||
|
||||
|
||||
public MouseHandler(NvConnection conn, JFrame parent) {
|
||||
this.conn = conn;
|
||||
this.parent = parent;
|
||||
@@ -44,9 +43,9 @@ public class MouseHandler implements MouseListener, MouseMotionListener {
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
robot.mouseMove(size.width / 2, size.height / 2);
|
||||
lastX = size.width / 2;
|
||||
lastY = size.height / 2;
|
||||
parent.getSize(size);
|
||||
moveMouse((int)parent.getLocation().getX() + (size.width/2),
|
||||
(int)parent.getLocation().getY() + (size.height/2));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,15 +105,24 @@ public class MouseHandler implements MouseListener, MouseMotionListener {
|
||||
|
||||
parent.getSize(size);
|
||||
|
||||
if (x < size.width / 2 - 500 || x > size.width / 2 + 500) {
|
||||
robot.mouseMove(size.width / 2, y);
|
||||
lastX = size.width / 2;
|
||||
int leftEdge = (int) parent.getLocation().getX();
|
||||
int rightEdge = leftEdge + size.width;
|
||||
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) {
|
||||
robot.mouseMove(x, size.height / 2);
|
||||
lastY = size.height / 2;
|
||||
if (y < upperEdge + 100 || y > lowerEdge - 100) {
|
||||
moveMouse((leftEdge+rightEdge)/2, (upperEdge+lowerEdge)/2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void moveMouse(int x, int y) {
|
||||
robot.mouseMove(x, y);
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user