From dd04e02f86566813d9b27525e36db1052ee65a16 Mon Sep 17 00:00:00 2001 From: Diego Waxemberg Date: Sat, 7 Dec 2013 21:22:52 -0500 Subject: [PATCH] added support for keyboard keys a-z --- limelight-pc/.classpath | 1 + limelight-pc/src/com/limelight/Limelight.java | 10 ++------ .../src/com/limelight/gui/StreamFrame.java | 9 ++++++- .../com/limelight/input/KeyboardHandler.java | 17 +++++++++---- .../limelight/input/KeyboardTranslator.java | 24 +++++++++++++++++++ 5 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 limelight-pc/src/com/limelight/input/KeyboardTranslator.java diff --git a/limelight-pc/.classpath b/limelight-pc/.classpath index e9503b8..5c9f161 100644 --- a/limelight-pc/.classpath +++ b/limelight-pc/.classpath @@ -4,5 +4,6 @@ + diff --git a/limelight-pc/src/com/limelight/Limelight.java b/limelight-pc/src/com/limelight/Limelight.java index f114aa5..da37547 100644 --- a/limelight-pc/src/com/limelight/Limelight.java +++ b/limelight-pc/src/com/limelight/Limelight.java @@ -1,13 +1,7 @@ package com.limelight; -import java.net.NetworkInterface; -import java.util.Enumeration; - import javax.swing.JOptionPane; -import javax.swing.JSpinner; import javax.swing.UIManager; -import javax.swing.UnsupportedLookAndFeelException; - import com.limelight.binding.PlatformBinding; import com.limelight.gui.MainFrame; import com.limelight.gui.StreamFrame; @@ -21,19 +15,19 @@ public class Limelight implements NvConnectionListener { private String host; private StreamFrame streamFrame; private NvConnection conn; - + public Limelight(String host) { this.host = host; } private void startUp() { streamFrame = new StreamFrame(); - streamFrame.build(); conn = new NvConnection(host, this); conn.start(PlatformBinding.getDeviceName(), streamFrame, VideoDecoderRenderer.FLAG_PREFER_QUALITY, PlatformBinding.getAudioRenderer(), PlatformBinding.getVideoDecoderRenderer()); + streamFrame.build(conn); } public static void createInstance(String host) { diff --git a/limelight-pc/src/com/limelight/gui/StreamFrame.java b/limelight-pc/src/com/limelight/gui/StreamFrame.java index dc07d85..f503428 100644 --- a/limelight-pc/src/com/limelight/gui/StreamFrame.java +++ b/limelight-pc/src/com/limelight/gui/StreamFrame.java @@ -5,10 +5,17 @@ import java.awt.Toolkit; import javax.swing.JFrame; +import com.limelight.input.KeyboardHandler; +import com.limelight.nvstream.NvConnection; + public class StreamFrame extends JFrame { private static final long serialVersionUID = 1L; - public void build() { + private KeyboardHandler keyboard; + + public void build(NvConnection conn) { + keyboard = new KeyboardHandler(conn); + this.addKeyListener(keyboard); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); this.setSize(1280,720); //This might break if the screen res is too small...not sure though diff --git a/limelight-pc/src/com/limelight/input/KeyboardHandler.java b/limelight-pc/src/com/limelight/input/KeyboardHandler.java index e0f5da5..6a900b3 100644 --- a/limelight-pc/src/com/limelight/input/KeyboardHandler.java +++ b/limelight-pc/src/com/limelight/input/KeyboardHandler.java @@ -3,17 +3,26 @@ package com.limelight.input; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; -public class KeyboardHandler implements KeyListener { +import com.limelight.nvstream.NvConnection; +public class KeyboardHandler implements KeyListener { + + private static KeyboardTranslator translator; + + public KeyboardHandler(NvConnection conn) { + translator = new KeyboardTranslator(conn); + } + @Override public void keyPressed(KeyEvent event) { - + short keyMap = translator.translate(event.getKeyCode()); + translator.sendKeyDown(keyMap); } @Override public void keyReleased(KeyEvent event) { - // TODO Auto-generated method stub - + short keyMap = translator.translate(event.getKeyCode()); + translator.sendKeyUp(keyMap); } @Override diff --git a/limelight-pc/src/com/limelight/input/KeyboardTranslator.java b/limelight-pc/src/com/limelight/input/KeyboardTranslator.java new file mode 100644 index 0000000..4677cd5 --- /dev/null +++ b/limelight-pc/src/com/limelight/input/KeyboardTranslator.java @@ -0,0 +1,24 @@ +package com.limelight.input; + +import java.awt.event.KeyEvent; + +import com.limelight.nvstream.NvConnection; +import com.limelight.nvstream.input.KeycodeTranslator; + +public class KeyboardTranslator extends KeycodeTranslator { + + public static final short KEYCODE_A = (short) 0x8041; + + public KeyboardTranslator(NvConnection conn) { + super(conn); + } + + @Override + public short translate(int keycode) { + if (keycode >= KeyEvent.VK_A && keycode <= KeyEvent.VK_Z) { + return (short) (KEYCODE_A + (short)(keycode - KeyEvent.VK_A)); + } + return 0; + } + +}