diff --git a/.gitignore b/.gitignore
index f36c267..9a016ff 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,26 @@
-/.metadata/
-/.recommenders/
+# Created by .ignore support plugin (hsz.mobi)
+### Java template
+# Compiled class file
+*.class
+
+# Log file
+*.log
+
+# BlueJ files
+*.ctxt
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.nar
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/KeyboardHookTest/KeyboardHookTest.iml b/KeyboardHookTest/KeyboardHookTest.iml
new file mode 100644
index 0000000..afcdbd9
--- /dev/null
+++ b/KeyboardHookTest/KeyboardHookTest.iml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/KeyboardHookTest/pom.xml b/KeyboardHookTest/pom.xml
new file mode 100644
index 0000000..08145f7
--- /dev/null
+++ b/KeyboardHookTest/pom.xml
@@ -0,0 +1,37 @@
+
+
+ 4.0.0
+
+ groupId
+ KeyboardHookTest
+ 1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 1.8
+
+
+
+
+
+
+
+ net.java.dev.jna
+ jna
+ 4.1.0
+
+
+
+ net.java.dev.jna
+ jna-platform
+ 4.1.0
+
+
+
+
\ No newline at end of file
diff --git a/KeyboardHookTest/src/main/java/KeyBoardHook.java b/KeyboardHookTest/src/main/java/KeyBoardHook.java
new file mode 100644
index 0000000..9e74c43
--- /dev/null
+++ b/KeyboardHookTest/src/main/java/KeyBoardHook.java
@@ -0,0 +1,66 @@
+import com.sun.jna.Pointer;
+import com.sun.jna.platform.win32.Kernel32;
+import com.sun.jna.platform.win32.User32;
+import com.sun.jna.platform.win32.WinDef.HMODULE;
+import com.sun.jna.platform.win32.WinDef.LPARAM;
+import com.sun.jna.platform.win32.WinDef.LRESULT;
+import com.sun.jna.platform.win32.WinDef.WPARAM;
+import com.sun.jna.platform.win32.WinUser;
+import com.sun.jna.platform.win32.WinUser.HHOOK;
+import com.sun.jna.platform.win32.WinUser.KBDLLHOOKSTRUCT;
+import com.sun.jna.platform.win32.WinUser.LowLevelKeyboardProc;
+import com.sun.jna.platform.win32.WinUser.MSG;
+
+public class KeyBoardHook {
+ static HHOOK hhk = null;
+ public static void main(String[] args) {
+ HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null);
+ User32 lib = User32.INSTANCE;
+ int result = 0;
+ LowLevelKeyboardProc rr = new LowLevelKeyboardProc() {
+ @Override
+ public LRESULT callback(int nCode, WPARAM wParam, KBDLLHOOKSTRUCT info) {
+ System.out.println(info.flags + " " + info.scanCode + " " + info.vkCode + " " + nCode + " " + wParam.intValue() + " " + wParam.doubleValue() );
+ try {
+ if (nCode >= 0) {
+ switch (wParam.intValue()) {
+ case WinUser.WM_KEYUP:
+ System.out.println(info.vkCode +"����" );
+ break;
+ case WinUser.WM_KEYDOWN:
+ System.out.println(info.vkCode +"����");
+ break;
+ case WinUser.WM_SYSKEYUP:
+ System.out.println(info.vkCode +"����----");
+ break;
+ case WinUser.WM_SYSKEYDOWN:
+ System.out.println(info.vkCode +"����----");
+ break;
+ }
+
+ }
+ } catch (Exception e) {
+
+ }
+
+ Pointer ptr = info.getPointer();
+
+ long peer = Pointer.nativeValue(ptr);
+
+ return lib.CallNextHookEx(hhk, nCode, wParam, new LPARAM(peer));
+ }
+ };
+ hhk = lib.SetWindowsHookEx(WinUser.WH_KEYBOARD_LL, rr, hMod, 0);
+ MSG msg = new MSG();
+ while ((result = lib.GetMessage(msg, null, 0, 0)) != 0) {
+ if (result == -1) {
+ System.err.println("error in get message");
+ break;
+ } else {
+ System.err.println("got message");
+ lib.TranslateMessage(msg);
+ lib.DispatchMessage(msg);
+ }
+ }
+ }
+}
diff --git a/RemoteControl-Client/RemoteControl-Client.iml b/RemoteControl-Client/RemoteControl-Client.iml
new file mode 100644
index 0000000..726407b
--- /dev/null
+++ b/RemoteControl-Client/RemoteControl-Client.iml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/RemoteControl-Client/pom.xml b/RemoteControl-Client/pom.xml
new file mode 100644
index 0000000..c7e5a83
--- /dev/null
+++ b/RemoteControl-Client/pom.xml
@@ -0,0 +1,44 @@
+
+
+ 4.0.0
+
+ groupId
+ RemoteControl-Client
+ 1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 1.8
+
+
+
+
+
+
+
+ net.java.dev.jna
+ jna
+ 4.1.0
+
+
+
+ net.java.dev.jna
+ jna-platform
+ 4.1.0
+
+
+
+ org.xerial.snappy
+ snappy-java
+ 1.1.4
+
+
+
+
+
\ No newline at end of file
diff --git a/RemoteControlClient/bin/exit.png b/RemoteControl-Client/res/exit.png
similarity index 100%
rename from RemoteControlClient/bin/exit.png
rename to RemoteControl-Client/res/exit.png
diff --git a/RemoteControlClient/bin/minimize.png b/RemoteControl-Client/res/minimize.png
similarity index 100%
rename from RemoteControlClient/bin/minimize.png
rename to RemoteControl-Client/res/minimize.png
diff --git a/RemoteControlClient/src/DebugMessage.java b/RemoteControl-Client/src/main/java/DebugMessage.java
similarity index 95%
rename from RemoteControlClient/src/DebugMessage.java
rename to RemoteControl-Client/src/main/java/DebugMessage.java
index 8f013ce..e7a7cde 100644
--- a/RemoteControlClient/src/DebugMessage.java
+++ b/RemoteControl-Client/src/main/java/DebugMessage.java
@@ -1,11 +1,11 @@
-
-public class DebugMessage {
- public static void printDebugMessage(String message) {
- System.out.println(message);
- }
-
- public static void printDebugMessage(Exception e) {
- e.getStackTrace();
- System.out.println(e.getMessage());
- }
-}
+
+public class DebugMessage {
+ public static void printDebugMessage(String message) {
+ System.out.println(message);
+ }
+
+ public static void printDebugMessage(Exception e) {
+ e.getStackTrace();
+ System.out.println(e.getMessage());
+ }
+}
diff --git a/RemoteControlClient/src/NetworkScreenClient.java b/RemoteControl-Client/src/main/java/NetworkScreenClient.java
similarity index 84%
rename from RemoteControlClient/src/NetworkScreenClient.java
rename to RemoteControl-Client/src/main/java/NetworkScreenClient.java
index 71ab59c..40d6d9f 100644
--- a/RemoteControlClient/src/NetworkScreenClient.java
+++ b/RemoteControl-Client/src/main/java/NetworkScreenClient.java
@@ -1,220 +1,202 @@
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.Insets;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.net.URL;
-
-import javax.swing.ImageIcon;
-import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JMenuBar;
-import javax.swing.JPanel;
-import javax.swing.JTextField;
-
-public class NetworkScreenClient extends JFrame {
- private static final long serialVersionUID = 1L;
- private ControlPanel controlPanel = new ControlPanel();
- private String myFont = "";
- private URL exitURL = getClass().getClassLoader().getResource("exit.png");
- private ImageIcon exitIcon = new ImageIcon(exitURL);
- private URL minimizeURL = getClass().getClassLoader().getResource("minimize.png");
- private ImageIcon minimizeIcon = new ImageIcon(minimizeURL);
- private JMenuBar jbar;
- private final int FRAME_WIDTH = 500;
- private final int FRAME_HEIGHT = 110;
- private Socket socket = new Socket();
- private Socket cursorsocket = new Socket();
- private Socket keyboardsocket = new Socket();
- private JFrame jFrame = this;
- private final static int SERVER_PORT = 9999;
- private final static int SERVER_CURSOR_PORT = SERVER_PORT-1;
- private final static int SERVER_KEYBOARD_PORT = SERVER_PORT-2;
- ScreenPanel screenPanel;
- public NetworkScreenClient() {
- setTitle("-");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setLayout(null);
- // createJMenu();
- setContentPane(controlPanel);
- setSize(FRAME_WIDTH, FRAME_HEIGHT);
- //setUndecorated(true);
- setVisible(true);
- addMouseMotionListener(new MouseAdapter() {
- @Override
- public void mouseDragged(MouseEvent e) {
- setLocation(e.getXOnScreen(), e.getYOnScreen());
- }
- });
- setLocation(400, 400);
-
- }
- public void createJMenu(){
- jbar = new JMenuBar();
- jbar.setPreferredSize(new Dimension(FRAME_WIDTH, 40));
- //jbar.setBackground(Color.yellow);
- jbar.setBorderPainted(false);
- jbar.setLayout(null);
-
- JLabel exitlabel = new JLabel(exitIcon);
-
- JLabel minilabel = new JLabel(minimizeIcon);
- jbar.add(exitlabel);
- jbar.add(minilabel);
- exitlabel.setBounds(FRAME_WIDTH-50, 10, 35, 35);
- minilabel.setBounds(FRAME_WIDTH-95, 10, 35, 35);
-
- exitlabel.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- if(e.getButton()==1){
- System.exit(1);
- }
- }
- });
- minilabel.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- if(e.getButton()==1){
- jFrame.setState(JFrame.ICONIFIED);
- }
- }
- });
- setJMenuBar(jbar);
- }
- class ControlPanel extends JPanel{
-
- private static final long serialVersionUID = 1L;
- private JTextField addressField = new JTextField(10);
- private JButton connectBtn = new JButton("Connect");
- private JButton exitBtn = new JButton("Exit");
- public ControlPanel() {
- setLayout(null);
-
- addressField.setBounds(0, 0, 200, FRAME_HEIGHT-50);
- connectBtn.setBounds(200, 0, 150, FRAME_HEIGHT-50);
- exitBtn.setBounds(350, 0, 150, FRAME_HEIGHT-50);
-
- addressField.setFont(new Font(myFont, Font.PLAIN, 20));
- connectBtn.setFont(new Font(myFont, Font.PLAIN, 20));
- exitBtn.setFont(new Font(myFont, Font.PLAIN, 20));
- addressField.setForeground(Color.LIGHT_GRAY);
-
- addressField.setText("123.123.123.123");
- addressField.setCaretPosition(0);
- addressField.setMargin(new Insets(1, 15, 1, 15));
- addressField.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- if(addressField.getText().equals("123.123.123.123") && addressField.getForeground() == Color.LIGHT_GRAY){
- addressField.setText("");
- addressField.setForeground(Color.BLACK);
- }
- else if(addressField.getText().equals("Connect Fail")){
- addressField.setText("");
- addressField.setForeground(Color.BLACK);
- }
- }
- });
- addressField.addKeyListener(new KeyAdapter() {
- @Override
- public void keyReleased(KeyEvent e) {
- if(addressField.getText().equals("")){
- addressField.setForeground(Color.LIGHT_GRAY);
- addressField.setText("123.123.123.123");
- addressField.setCaretPosition(0);
- }
- }
-
- @Override
- public void keyPressed(KeyEvent e) {
- if(e.getKeyCode() == KeyEvent.VK_ENTER){
- connectBtn.doClick();
- }
- if(addressField.getText().equals("123.123.123.123") && addressField.getForeground() == Color.LIGHT_GRAY){
- addressField.setText("");
- addressField.setForeground(Color.BLACK);
- }
-
- }
- });
-
- add(addressField);
- add(connectBtn);
- add(exitBtn);
- exitBtn.setEnabled(false);
- connectBtn.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- /*GraphicsDevice device = GraphicsEnvironment
- .getLocalGraphicsEnvironment().getScreenDevices()[0];
- device.setFullScreenWindow(jFrame);*/
-
- InetSocketAddress inetAddress;
- InetSocketAddress inetCursorAddress;
- InetSocketAddress inetKeyboardAddress;
- if(addressField.getText().equals("123.123.123.123") && addressField.getForeground() == Color.LIGHT_GRAY){
- inetAddress = new InetSocketAddress("localhost", SERVER_PORT);
- inetCursorAddress = new InetSocketAddress("localhost", SERVER_CURSOR_PORT);
- inetKeyboardAddress = new InetSocketAddress("localhost", SERVER_KEYBOARD_PORT);
- }
- else{
- inetAddress = new InetSocketAddress(addressField.getText(), SERVER_PORT);
- inetCursorAddress = new InetSocketAddress(addressField.getText(), SERVER_CURSOR_PORT);
- inetKeyboardAddress = new InetSocketAddress(addressField.getText(), SERVER_KEYBOARD_PORT);
- }
- try {
- socket.connect(inetAddress, 1000);
- cursorsocket.connect(inetCursorAddress, 1000);
- keyboardsocket.connect(inetKeyboardAddress,1000);
- } catch (IOException e1) {
- DebugMessage.printDebugMessage(e1);
- addressField.setText("Connect Fail");
- socket = new Socket();
- cursorsocket = new Socket();
- keyboardsocket = new Socket();
- }
- if(socket.isConnected()){
- addressField.setText("Connect Sucess!");
- System.out.println("");
- try {
- Thread.sleep(500);
- screenPanel = new ScreenPanel(jFrame, socket,cursorsocket,keyboardsocket);
- setJMenuBar(null);
-
- jFrame.setContentPane(screenPanel);
- screenPanel.requestFocus();
- //setExtendedState(JFrame.MAXIMIZED_BOTH);
- jFrame.revalidate();
- screenPanel.requestFocus();
-
-
- } catch (InterruptedException e1) {
- DebugMessage.printDebugMessage(e1);
- }
- }
-
- }
- });
- exitBtn.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- System.exit(1);
- }
- });
- }
- }
- public static void main(String[] args) {
- new NetworkScreenClient();
- }
-}
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.URL;
+
+public class NetworkScreenClient extends JFrame {
+ private ControlPanel controlPanel = new ControlPanel();
+ private String myFont = "맑은고딕";
+ private URL exitURL = getClass().getClassLoader().getResource("exit.png");
+ private ImageIcon exitIcon = new ImageIcon(exitURL);
+ private URL minimizeURL = getClass().getClassLoader().getResource("minimize.png");
+ private ImageIcon minimizeIcon = new ImageIcon(minimizeURL);
+ private JMenuBar jbar;
+ private final int FRAME_WIDTH = 500;
+ private final int FRAME_HEIGHT = 110;
+ private Socket socket = new Socket();
+ private Socket cursorsocket = new Socket();
+ private Socket keyboardsocket = new Socket();
+ private JFrame jFrame = this;
+ private final static int SERVER_PORT = 9999;
+ private final static int SERVER_CURSOR_PORT = SERVER_PORT-1;
+ private final static int SERVER_KEYBOARD_PORT = SERVER_PORT-2;
+ ScreenPanel screenPanel;
+ public NetworkScreenClient() {
+ setTitle("원격지원-지원지");
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ setLayout(null);
+ // createJMenu();
+ setContentPane(controlPanel);
+ setSize(FRAME_WIDTH, FRAME_HEIGHT);
+ //setUndecorated(true);
+ setVisible(true);
+ addMouseMotionListener(new MouseAdapter() {
+ @Override
+ public void mouseDragged(MouseEvent e) {
+ setLocation(e.getXOnScreen(), e.getYOnScreen());
+ }
+ });
+ setLocation(400, 400);
+
+ }
+ public void createJMenu(){
+ jbar = new JMenuBar();
+ jbar.setPreferredSize(new Dimension(FRAME_WIDTH, 40));
+ //jbar.setBackground(Color.yellow);
+ jbar.setBorderPainted(false);
+ jbar.setLayout(null);
+
+ JLabel exitlabel = new JLabel(exitIcon);
+
+ JLabel minilabel = new JLabel(minimizeIcon);
+ jbar.add(exitlabel);
+ jbar.add(minilabel);
+ exitlabel.setBounds(FRAME_WIDTH-50, 10, 35, 35);
+ minilabel.setBounds(FRAME_WIDTH-95, 10, 35, 35);
+
+ exitlabel.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if(e.getButton()==1){
+ System.exit(1);
+ }
+ }
+ });
+ minilabel.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if(e.getButton()==1){
+ jFrame.setState(JFrame.ICONIFIED);
+ }
+ }
+ });
+ setJMenuBar(jbar);
+ }
+ class ControlPanel extends JPanel{
+ JTextField addressField = new JTextField(10);
+ JButton connectBtn = new JButton("Connect");
+ JButton exitBtn = new JButton("Exit");
+ public ControlPanel() {
+ setLayout(null);
+
+ addressField.setBounds(0, 0, 200, FRAME_HEIGHT-50);
+ connectBtn.setBounds(200, 0, 150, FRAME_HEIGHT-50);
+ exitBtn.setBounds(350, 0, 150, FRAME_HEIGHT-50);
+
+ addressField.setFont(new Font(myFont, Font.PLAIN, 20));
+ connectBtn.setFont(new Font(myFont, Font.PLAIN, 20));
+ exitBtn.setFont(new Font(myFont, Font.PLAIN, 20));
+ addressField.setForeground(Color.LIGHT_GRAY);
+
+ addressField.setText("123.123.123.123");
+ addressField.setCaretPosition(0);
+ addressField.setMargin(new Insets(1, 15, 1, 15));
+ addressField.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent arg0) {
+ if(addressField.getText().equals("123.123.123.123") && addressField.getForeground() == Color.LIGHT_GRAY){
+ addressField.setText("");
+ addressField.setForeground(Color.BLACK);
+ }
+ else if(addressField.getText().equals("Connect Fail")){
+ addressField.setText("");
+ addressField.setForeground(Color.BLACK);
+ }
+ }
+ });
+ addressField.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyReleased(KeyEvent e) {
+ if(addressField.getText().equals("")){
+ addressField.setForeground(Color.LIGHT_GRAY);
+ addressField.setText("123.123.123.123");
+ addressField.setCaretPosition(0);
+ }
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ if(e.getKeyCode() == KeyEvent.VK_ENTER){
+ connectBtn.doClick();
+ }
+ if(addressField.getText().equals("123.123.123.123") && addressField.getForeground() == Color.LIGHT_GRAY){
+ addressField.setText("");
+ addressField.setForeground(Color.BLACK);
+ }
+
+ }
+ });
+
+ add(addressField);
+ add(connectBtn);
+ add(exitBtn);
+ exitBtn.setEnabled(false);
+ connectBtn.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ /*GraphicsDevice device = GraphicsEnvironment
+ .getLocalGraphicsEnvironment().getScreenDevices()[0];
+ device.setFullScreenWindow(jFrame);*/
+
+ InetSocketAddress inetAddress;
+ InetSocketAddress inetCursorAddress;
+ InetSocketAddress inetKeyboardAddress;
+ if(addressField.getText().equals("123.123.123.123") && addressField.getForeground() == Color.LIGHT_GRAY){
+ inetAddress = new InetSocketAddress("localhost", SERVER_PORT);
+ inetCursorAddress = new InetSocketAddress("localhost", SERVER_CURSOR_PORT);
+ inetKeyboardAddress = new InetSocketAddress("localhost", SERVER_KEYBOARD_PORT);
+ }
+ else{
+ inetAddress = new InetSocketAddress(addressField.getText(), SERVER_PORT);
+ inetCursorAddress = new InetSocketAddress(addressField.getText(), SERVER_CURSOR_PORT);
+ inetKeyboardAddress = new InetSocketAddress(addressField.getText(), SERVER_KEYBOARD_PORT);
+ }
+ try {
+ socket.connect(inetAddress, 1000);
+ cursorsocket.connect(inetCursorAddress, 1000);
+ keyboardsocket.connect(inetKeyboardAddress,1000);
+ } catch (IOException e1) {
+ DebugMessage.printDebugMessage(e1);
+ addressField.setText("Connect Fail");
+ socket = new Socket();
+ cursorsocket = new Socket();
+ keyboardsocket = new Socket();
+ }
+ if(socket.isConnected()){
+ addressField.setText("Connect Sucess!");
+ System.out.println("연결됨");
+ try {
+ Thread.sleep(500);
+ screenPanel = new ScreenPanel(jFrame, socket,cursorsocket,keyboardsocket);
+ setJMenuBar(null);
+
+ jFrame.setContentPane(screenPanel);
+ screenPanel.requestFocus();
+ //setExtendedState(JFrame.MAXIMIZED_BOTH);
+ jFrame.revalidate();
+ screenPanel.requestFocus();
+
+
+ } catch (InterruptedException e1) {
+ DebugMessage.printDebugMessage(e1);
+ }
+ }
+
+ }
+ });
+ exitBtn.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ System.exit(1);
+ }
+ });
+ }
+ }
+ public static void main(String[] args) {
+ new NetworkScreenClient();
+ }
+}
diff --git a/RemoteControlClient/src/ScreenPanel.java b/RemoteControl-Client/src/main/java/ScreenPanel.java
similarity index 89%
rename from RemoteControlClient/src/ScreenPanel.java
rename to RemoteControl-Client/src/main/java/ScreenPanel.java
index 23c0ed3..7a976fb 100644
--- a/RemoteControlClient/src/ScreenPanel.java
+++ b/RemoteControl-Client/src/main/java/ScreenPanel.java
@@ -1,407 +1,407 @@
-
-import java.awt.Font;
-import java.awt.Graphics;
-import java.awt.Point;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseMotionListener;
-import java.awt.event.MouseWheelEvent;
-import java.awt.event.MouseWheelListener;
-import java.awt.image.BufferedImage;
-import java.awt.image.DataBufferByte;
-import java.awt.image.Raster;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.net.Socket;
-import java.util.Vector;
-
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-
-import org.xerial.snappy.Snappy;
-
-import com.sun.jna.Library;
-import com.sun.jna.Native;
-import com.sun.jna.Pointer;
-import com.sun.jna.platform.win32.Kernel32;
-import com.sun.jna.platform.win32.User32;
-import com.sun.jna.platform.win32.WinDef.HMODULE;
-import com.sun.jna.platform.win32.WinDef.LPARAM;
-import com.sun.jna.platform.win32.WinDef.LRESULT;
-import com.sun.jna.platform.win32.WinDef.WPARAM;
-import com.sun.jna.platform.win32.WinUser;
-import com.sun.jna.platform.win32.WinUser.HHOOK;
-import com.sun.jna.platform.win32.WinUser.KBDLLHOOKSTRUCT;
-import com.sun.jna.platform.win32.WinUser.LowLevelKeyboardProc;
-import com.sun.jna.platform.win32.WinUser.MSG;
-
-class ScreenPanel extends JPanel implements Runnable {
- private static final long serialVersionUID = 1L;
-
- private BufferedImage screenImage;
- private JLabel FPSlabel;
- private int FPScount = 0;
- private BufferedImage image;
- private DataOutputStream mouseOutputStream;
- private DataOutputStream keyboardOutputStream;
- private DataInputStream dataInputStream;
- private int image_Width = 1280;
- private int image_Height = 720;
- private byte imageByte2[] = new byte[6220800];
- private int mouseX = 0, mouseY = 0;
- private int mouseButton = 0;
- private int screen_Width = 1920;
- private int screen_Height = 1080;
- private Boolean isCompress = true;
- private final int MOUSE_MOVE = 1;
- private final int MOUSE_PRESSD = 2;
- private final int MOUSE_RELEASED = 3;
- private final int MOUSE_DOWN_WHEEL = 4;
- private final int MOUSE_UP_WHEEL = 5;
- private final int KEY_PRESSED = 6;
- private final int KEY_RELEASED = 7;
- private Vector imgVec = new Vector<>();
- ScreenPanel ppp = this;
- User32 lib = User32.INSTANCE;
- User32jna u32 = User32jna.INSTANCE;
- HHOOK hhk = null;
- HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null);
- Thread thread;
- Object lock = new Object();
- public interface User32jna extends Library {
- User32jna INSTANCE = (User32jna) Native.loadLibrary("user32.dll", User32jna.class);
-
- // User32jna INSTANCE = (User32jna)
- // Native.loadLibrary("user32.dll",User32jna.class);
- public void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
- }
-
- public ScreenPanel(JFrame frame, Socket socket, Socket cursorSocket, Socket keyboardSocket) {
- setLayout(null);
- FPSlabel = new JLabel("FPS : " + Integer.toString(FPScount));
- FPSlabel.setFont(new Font("", Font.BOLD, 20));
- FPSlabel.setBounds(10, 10, 100, 50);
- add(FPSlabel);
- System.out.println(socket.getInetAddress());
- try {
- setLayout(null);
- socket.setTcpNoDelay(true);
- /*
- * socket.setSendBufferSize(1024 * 1024 * 10);
- * socket.setReceiveBufferSize(1024 * 1024 * 10);
- */
- mouseOutputStream = new DataOutputStream(cursorSocket.getOutputStream());
- keyboardOutputStream = new DataOutputStream(keyboardSocket.getOutputStream());
- dataInputStream = new DataInputStream(socket.getInputStream());
- } catch (IOException e) {
- DebugMessage.printDebugMessage(e);
- }
- thread = new Thread(this);
- thread.start();
- KeyboardThread keyboardThread = new KeyboardThread();
- keyboardThread.start();
- FPSCheckThread fpsCheckThread = new FPSCheckThread();
- fpsCheckThread.start();
- showThread ss = new showThread();
- //showThread ss2 = new showThread();
- ss.start();
- //ss2.start();
- // lib.UnhookWindowsHookEx(hhk);
- addMouseWheelListener(new MouseWheelListener() {
-
- @Override
- public void mouseWheelMoved(MouseWheelEvent e) {
- try {
- int n = e.getWheelRotation();
- if (n < 0) {
- mouseOutputStream.writeInt(MOUSE_DOWN_WHEEL);
- } else {
- mouseOutputStream.writeInt(MOUSE_UP_WHEEL);
- }
-
- } catch (IOException e1) {
- DebugMessage.printDebugMessage(e1);
- }
- }
- });
- addMouseMotionListener(new MouseMotionListener() {
-
- @Override
- public void mouseMoved(MouseEvent e) {
- // 800 300 1920 1080
- // x y x y
- mouseX = e.getX() * screen_Width / getWidth();
- mouseY = e.getY() * screen_Height / getHeight();
-
- try {
- mouseOutputStream.writeInt(MOUSE_MOVE);
- mouseOutputStream.writeInt(mouseX);
- mouseOutputStream.writeInt(mouseY);
- } catch (IOException e1) {
- DebugMessage.printDebugMessage(e1);
- }
- }
-
- @Override
- public void mouseDragged(MouseEvent e) {
- mouseX = e.getX() * screen_Width / getWidth();
- mouseY = e.getY() * screen_Height / getHeight();
- try {
- mouseOutputStream.writeInt(MOUSE_MOVE);
- mouseOutputStream.writeInt(mouseX);
- mouseOutputStream.writeInt(mouseY);
- } catch (IOException e1) {
- DebugMessage.printDebugMessage(e1);
- }
-
- }
- });
- addMouseListener(new MouseAdapter() {
-
- @Override
- public void mousePressed(MouseEvent e) {
- mouseButton = e.getButton();
- try {
- mouseOutputStream.writeInt(MOUSE_PRESSD);
- mouseOutputStream.writeInt(mouseButton);
- } catch (IOException e1) {
- DebugMessage.printDebugMessage(e1);
- }
- }
-
- @Override
- public void mouseReleased(MouseEvent e) {
- mouseButton = e.getButton();
- try {
- mouseOutputStream.writeInt(MOUSE_RELEASED);
- mouseOutputStream.writeInt(mouseButton);
- } catch (IOException e1) {
- DebugMessage.printDebugMessage(e1);
- }
- }
- });
-
- /*
- * addKeyListener(new KeyAdapter() {
- *
- * @Override public void keyTyped(KeyEvent e) {
- * //System.out.println("type" + e.getKeyCode() + " " + e.getKeyChar()
- * + " " + e.getID() + " " + e.getModifiers()+ " "+
- * e.getKeyLocation() + " " + e.getExtendedKeyCode());
- *
- * }
- *
- * @Override public void keyPressed(KeyEvent e) { try {
- * //System.out.println("press" + e.getKeyCode() + " " + e.getKeyChar()
- * + " " + e.getID() + " " + e.getModifiers()+ " "+
- * e.getKeyLocation() + " " + e.getExtendedKeyCode());
- * if(e.getKeyCode() !=0){ dataOutputStream.writeInt(KEY_PRESSED);
- * dataOutputStream.writeInt(e.getKeyCode()); } } catch (IOException e1)
- * { DebugMessage.printDebugMessage(e1); } }
- *
- * @Override public void keyReleased(KeyEvent e) { try {
- * //System.out.println("released" + e.getKeyCode() + " " +
- * e.getKeyChar() + " " + e.getID() + " " + e.getModifiers()+ " "+
- * e.getKeyLocation() + " " + e.getExtendedKeyCode());
- * if(e.getKeyCode() ==0){ if(count >= 1){ count = 0; return; }
- * //System.out.println(t.getLocale().toString() + " " +
- * t.getLocale().getCountry() + " " +
- * t.getLocale().getDisplayCountry());
- * //System.out.println("ѱŰ -"); count = 1; u32.keybd_event((byte)
- * 0x15, (byte)0, 0, 0);//ffDDDddSS u32.keybd_event((byte) 0x15,
- * (byte)00, (byte)0x0002, 0);//
- * dataOutputStream.writeInt(KEY_CHANGE_LANGUAGE);
- *
- * } else{ dataOutputStream.writeInt(KEY_RELEASED);
- * dataOutputStream.writeInt(e.getKeyCode()); }
- *
- * } catch (Exception e1) { DebugMessage.printDebugMessage(e1); } } });
- */
-
- requestFocus();
- }
-
- public void run() {
- try {
- screen_Width = dataInputStream.readInt();
- screen_Height = dataInputStream.readInt();
- image_Width = dataInputStream.readInt();
- image_Height = dataInputStream.readInt();
- isCompress = dataInputStream.readBoolean();
- } catch (IOException e1) {
- DebugMessage.printDebugMessage(e1);
- }
-
- while (true) {
-
- try {// 172.30.1.54
- if (dataInputStream.available() > 0) {
- int length = 0;
- if (isCompress) {
-
- length = dataInputStream.readInt();
-
- byte imageByte[] = new byte[length];
-
- dataInputStream.readFully(imageByte, 0, length);
-
- imgVec.addElement(imageByte);
- //System.out.println(imgVec.size());
-
- if (imgVec.size() > 1) {
- synchronized (lock) {
-
- lock.wait();
- }
- }
-
- } else {
- length = dataInputStream.readInt();
- dataInputStream.readFully(imageByte2, 0, length);
- screenImage = new BufferedImage(image_Width, image_Height, BufferedImage.TYPE_3BYTE_BGR);
- screenImage.setData(Raster.createRaster(screenImage.getSampleModel(),
- new DataBufferByte(imageByte2, imageByte2.length), new Point()));
- }
- //thread.sleep(20);
- }
-
- } catch (Exception e) {
- //DebugMessage.printDebugMessage(e);
- }
-
- }
- }
-
- class showThread extends Thread {
- byte imageByte[];
- byte uncompressImageByte[];
- public void run() {
-
- while (true) {
- try {
-
- imageByte = imgVec.get(0);
- //System.out.println(imgVec.size());
- uncompressImageByte = Snappy.uncompress(imageByte);
- if (imgVec.size() > 0){
- imgVec.remove(0);
- //System.out.println(imgVec.size());
- }
- screenImage = new BufferedImage(image_Width, image_Height, BufferedImage.TYPE_3BYTE_BGR);
- screenImage.setData(Raster.createRaster(screenImage.getSampleModel(),
- new DataBufferByte(uncompressImageByte, uncompressImageByte.length), new Point()));
- // System.out.println(imgVec.size() + " " + thread.getState());
- if (imgVec.size() == 1) {
- synchronized (lock) {
- //System.out.println(thread.getState());
- //System.out.println("notify~~~~~~~~");
- lock.notify();
- }
- }
- if(screenImage != null){
- image = screenImage;
- FPScount++;
- repaint();
- }
-
- } catch (Exception e) {
-
- }
- // decompress(imageByte);
- }
- }
- }
-
- class FPSCheckThread extends Thread {
- public void run() {
- while (true) {
- try {
- sleep(1000);
- FPSlabel.setText("FPS : " + Integer.toString(FPScount));
- // repaint();
- // System.out.println("FPS : " + FPScount);
- FPScount = 0;
- } catch (InterruptedException e) {
- }
- }
- }
- }
-
- class KeyboardThread extends Thread {
- int result;
- int keypress = 0;
-
- public void run() {
- LowLevelKeyboardProc rr = new LowLevelKeyboardProc() {
-
- @Override
- public LRESULT callback(int nCode, WPARAM wParam, KBDLLHOOKSTRUCT info) {
- try {
- System.out.println(info.vkCode);
- if (info.vkCode == 21) {
- System.out.println("ѿ");
- if (keypress == 0) {
- u32.keybd_event((byte) 0x15, (byte) 0, 0, 0);// ffDDDddSS
- u32.keybd_event((byte) 0x15, (byte) 00, (byte) 0x0002, 0);//
- keypress++;
- } else {
- keypress = 0;
- }
-
- }
- if (nCode >= 0) {
-
- switch (wParam.intValue()) {
- case WinUser.WM_KEYUP:
- keyboardOutputStream.writeInt(KEY_RELEASED);
- keyboardOutputStream.writeInt(info.vkCode);
- break;
- case WinUser.WM_KEYDOWN:
- keyboardOutputStream.writeInt(KEY_PRESSED);
- keyboardOutputStream.writeInt(info.vkCode);
- break;
- case WinUser.WM_SYSKEYUP:
- keyboardOutputStream.writeInt(KEY_RELEASED);
- keyboardOutputStream.writeInt(info.vkCode);
- break;
- case WinUser.WM_SYSKEYDOWN:
- keyboardOutputStream.writeInt(KEY_PRESSED);
- keyboardOutputStream.writeInt(info.vkCode);
- break;
- }
-
- }
- } catch (Exception e) {
- DebugMessage.printDebugMessage(e);
- }
-
- Pointer ptr = info.getPointer();
-
- long peer = Pointer.nativeValue(ptr);
-
- return lib.CallNextHookEx(hhk, nCode, wParam, new LPARAM(peer));
- }
- };
- hhk = lib.SetWindowsHookEx(WinUser.WH_KEYBOARD_LL, rr, hMod, 0);
- MSG msg = new MSG();
- while ((result = lib.GetMessage(msg, null, 0, 0)) != 0) {
- if (result == -1) {
- System.err.println("error in get message");
- break;
- } else {
- System.err.println("got message");
- lib.TranslateMessage(msg);
- lib.DispatchMessage(msg);
- }
- }
- }
- }
-
- @Override
- protected void paintComponent(Graphics g) {
- super.paintComponent(g);
- g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
- }
-}
+import com.sun.jna.Library;
+import com.sun.jna.Native;
+import com.sun.jna.Pointer;
+import com.sun.jna.platform.win32.Kernel32;
+import com.sun.jna.platform.win32.User32;
+import com.sun.jna.platform.win32.WinDef.HMODULE;
+import com.sun.jna.platform.win32.WinDef.LPARAM;
+import com.sun.jna.platform.win32.WinDef.LRESULT;
+import com.sun.jna.platform.win32.WinDef.WPARAM;
+import com.sun.jna.platform.win32.WinUser;
+import com.sun.jna.platform.win32.WinUser.HHOOK;
+import com.sun.jna.platform.win32.WinUser.KBDLLHOOKSTRUCT;
+import com.sun.jna.platform.win32.WinUser.LowLevelKeyboardProc;
+import com.sun.jna.platform.win32.WinUser.MSG;
+import org.xerial.snappy.Snappy;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBufferByte;
+import java.awt.image.Raster;
+import java.io.*;
+import java.net.Socket;
+import java.util.Vector;
+
+class ScreenPanel extends JPanel implements Runnable {
+ private Socket socket;
+ private Socket cursorSocket;
+ private Socket keyboardSocket;
+ private BufferedImage screenImage;
+ private JFrame frame;
+ private JLabel FPSlabel;
+ private int FPScount = 0;
+ private BufferedImage image;
+ private DataOutputStream mouseOutputStream;
+ private DataOutputStream keyboardOutputStream;
+ private DataInputStream dataInputStream;
+ private ObjectInputStream objectInputStream;
+ private BufferedWriter bufferedWriter;
+ private int image_Width = 1280;
+ private int image_Height = 720;
+ private byte imageByte2[] = new byte[6220800];
+ private int mouseX = 0, mouseY = 0;
+ private int mouseClickCount = 0;
+ private int mouseButton = 0;
+ private int mousePosition = 0; // 1 == move 2 == click
+ private int screen_Width = 1920;
+ private int screen_Height = 1080;
+ private Boolean isCompress = true;
+ private final int MOUSE_MOVE = 1;
+ private final int MOUSE_PRESSD = 2;
+ private final int MOUSE_RELEASED = 3;
+ private final int MOUSE_DOWN_WHEEL = 4;
+ private final int MOUSE_UP_WHEEL = 5;
+ private final int KEY_PRESSED = 6;
+ private final int KEY_RELEASED = 7;
+ private final int KEY_CHANGE_LANGUAGE = 8;
+ private int count = 0;
+ private Vector imgVec = new Vector<>();
+ ScreenPanel ppp = this;
+ User32 lib = User32.INSTANCE;
+ User32jna u32 = User32jna.INSTANCE;
+ HHOOK hhk = null;
+ HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null);
+ Thread thread;
+ Object lock = new Object();
+ public interface User32jna extends Library {
+ User32jna INSTANCE = (User32jna) Native.loadLibrary("user32.dll", User32jna.class);
+
+ // User32jna INSTANCE = (User32jna)
+ // Native.loadLibrary("user32.dll",User32jna.class);
+ public void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
+ }
+
+ public ScreenPanel(JFrame frame, Socket socket, Socket cursorSocket, Socket keyboardSocket) {
+ setLayout(null);
+ this.socket = socket;
+ this.cursorSocket = cursorSocket;
+ this.keyboardSocket = keyboardSocket;
+ this.frame = frame;
+ FPSlabel = new JLabel("FPS : " + Integer.toString(FPScount));
+ FPSlabel.setFont(new Font("맑은고딕", Font.BOLD, 20));
+ FPSlabel.setBounds(10, 10, 100, 50);
+ add(FPSlabel);
+ System.out.println(socket.getInetAddress());
+ try {
+ setLayout(null);
+ socket.setTcpNoDelay(true);
+ /*
+ * socket.setSendBufferSize(1024 * 1024 * 10);
+ * socket.setReceiveBufferSize(1024 * 1024 * 10);
+ */
+ mouseOutputStream = new DataOutputStream(cursorSocket.getOutputStream());
+ keyboardOutputStream = new DataOutputStream(keyboardSocket.getOutputStream());
+ dataInputStream = new DataInputStream(socket.getInputStream());
+ objectInputStream = new ObjectInputStream(socket.getInputStream());
+ } catch (IOException e) {
+ DebugMessage.printDebugMessage(e);
+ }
+ thread = new Thread(this);
+ thread.start();
+ KeyboardThread keyboardThread = new KeyboardThread();
+ keyboardThread.start();
+ FPSCheckThread fpsCheckThread = new FPSCheckThread();
+ fpsCheckThread.start();
+ showThread ss = new showThread();
+ //showThread ss2 = new showThread();
+ ss.start();
+ //ss2.start();
+ // lib.UnhookWindowsHookEx(hhk);
+ addMouseWheelListener(new MouseWheelListener() {
+
+ @Override
+ public void mouseWheelMoved(MouseWheelEvent e) {
+ try {
+ int n = e.getWheelRotation();
+ if (n < 0) {
+ mouseOutputStream.writeInt(MOUSE_DOWN_WHEEL);
+ } else {
+ mouseOutputStream.writeInt(MOUSE_UP_WHEEL);
+ }
+
+ } catch (IOException e1) {
+ DebugMessage.printDebugMessage(e1);
+ }
+ }
+ });
+ addMouseMotionListener(new MouseMotionListener() {
+
+ @Override
+ public void mouseMoved(MouseEvent e) {
+ // 800 300 1920 1080
+ // x y x y
+ mouseX = e.getX() * screen_Width / getWidth();
+ mouseY = e.getY() * screen_Height / getHeight();
+
+ try {
+ mouseOutputStream.writeInt(MOUSE_MOVE);
+ mouseOutputStream.writeInt(mouseX);
+ mouseOutputStream.writeInt(mouseY);
+ } catch (IOException e1) {
+ DebugMessage.printDebugMessage(e1);
+ }
+ }
+
+ @Override
+ public void mouseDragged(MouseEvent e) {
+ mouseX = e.getX() * screen_Width / getWidth();
+ mouseY = e.getY() * screen_Height / getHeight();
+ try {
+ mouseOutputStream.writeInt(MOUSE_MOVE);
+ mouseOutputStream.writeInt(mouseX);
+ mouseOutputStream.writeInt(mouseY);
+ } catch (IOException e1) {
+ DebugMessage.printDebugMessage(e1);
+ }
+
+ }
+ });
+ addMouseListener(new MouseAdapter() {
+
+ @Override
+ public void mousePressed(MouseEvent e) {
+ mouseButton = e.getButton();
+ try {
+ mouseOutputStream.writeInt(MOUSE_PRESSD);
+ mouseOutputStream.writeInt(mouseButton);
+ } catch (IOException e1) {
+ DebugMessage.printDebugMessage(e1);
+ }
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ mouseButton = e.getButton();
+ try {
+ mouseOutputStream.writeInt(MOUSE_RELEASED);
+ mouseOutputStream.writeInt(mouseButton);
+ } catch (IOException e1) {
+ DebugMessage.printDebugMessage(e1);
+ }
+ }
+ });
+
+ /*
+ * addKeyListener(new KeyAdapter() {
+ *
+ * @Override public void keyTyped(KeyEvent e) {
+ * //System.out.println("type" + e.getKeyCode() + " " + e.getKeyChar()
+ * + " " + e.getID() + " " + e.getModifiers()+ " "+
+ * e.getKeyLocation() + " " + e.getExtendedKeyCode());
+ *
+ * }
+ *
+ * @Override public void keyPressed(KeyEvent e) { try {
+ * //System.out.println("press" + e.getKeyCode() + " " + e.getKeyChar()
+ * + " " + e.getID() + " " + e.getModifiers()+ " "+
+ * e.getKeyLocation() + " " + e.getExtendedKeyCode());
+ * if(e.getKeyCode() !=0){ dataOutputStream.writeInt(KEY_PRESSED);
+ * dataOutputStream.writeInt(e.getKeyCode()); } } catch (IOException e1)
+ * { DebugMessage.printDebugMessage(e1); } }
+ *
+ * @Override public void keyReleased(KeyEvent e) { try {
+ * //System.out.println("released" + e.getKeyCode() + " " +
+ * e.getKeyChar() + " " + e.getID() + " " + e.getModifiers()+ " "+
+ * e.getKeyLocation() + " " + e.getExtendedKeyCode());
+ * if(e.getKeyCode() ==0){ if(count >= 1){ count = 0; return; }
+ * //System.out.println(t.getLocale().toString() + " " +
+ * t.getLocale().getCountry() + " " +
+ * t.getLocale().getDisplayCountry());
+ * //System.out.println("한글키 눌림-보냄"); count = 1; u32.keybd_event((byte)
+ * 0x15, (byte)0, 0, 0);//누름ffDDDddSS u32.keybd_event((byte) 0x15,
+ * (byte)00, (byte)0x0002, 0);// 누름 해제
+ * dataOutputStream.writeInt(KEY_CHANGE_LANGUAGE);
+ *
+ * } else{ dataOutputStream.writeInt(KEY_RELEASED);
+ * dataOutputStream.writeInt(e.getKeyCode()); }
+ *
+ * } catch (Exception e1) { DebugMessage.printDebugMessage(e1); } } });
+ */
+
+ requestFocus();
+ }
+
+ public void run() {
+ try {
+ screen_Width = dataInputStream.readInt();
+ screen_Height = dataInputStream.readInt();
+ image_Width = dataInputStream.readInt();
+ image_Height = dataInputStream.readInt();
+ isCompress = dataInputStream.readBoolean();
+ } catch (IOException e1) {
+ DebugMessage.printDebugMessage(e1);
+ }
+
+ while (true) {
+
+ try {// 172.30.1.54
+ if (dataInputStream.available() > 0) {
+ int length = 0;
+ if (isCompress) {
+
+ length = dataInputStream.readInt();
+
+ byte imageByte[] = new byte[length];
+
+ dataInputStream.readFully(imageByte, 0, length);
+
+ imgVec.addElement(imageByte);
+ //System.out.println(imgVec.size());
+
+ if (imgVec.size() > 1) {
+ synchronized (lock) {
+
+ lock.wait();
+ }
+ }
+
+ } else {
+ length = dataInputStream.readInt();
+ dataInputStream.readFully(imageByte2, 0, length);
+ screenImage = new BufferedImage(image_Width, image_Height, BufferedImage.TYPE_3BYTE_BGR);
+ screenImage.setData(Raster.createRaster(screenImage.getSampleModel(),
+ new DataBufferByte(imageByte2, imageByte2.length), new Point()));
+ }
+ //thread.sleep(20);
+ }
+
+ } catch (Exception e) {
+ //DebugMessage.printDebugMessage(e);
+ }
+
+ }
+ }
+
+ class showThread extends Thread {
+ byte imageByte[];
+ byte uncompressImageByte[];
+ public void run() {
+
+ while (true) {
+ try {
+
+ imageByte = imgVec.get(0);
+ //System.out.println(imgVec.size());
+ uncompressImageByte = Snappy.uncompress(imageByte);
+ if (imgVec.size() > 0){
+ imgVec.remove(0);
+ //System.out.println(imgVec.size());
+ }
+ screenImage = new BufferedImage(image_Width, image_Height, BufferedImage.TYPE_3BYTE_BGR);
+ screenImage.setData(Raster.createRaster(screenImage.getSampleModel(),
+ new DataBufferByte(uncompressImageByte, uncompressImageByte.length), new Point()));
+ // System.out.println(imgVec.size() + " " + thread.getState());
+ if (imgVec.size() == 1) {
+ synchronized (lock) {
+ //System.out.println(thread.getState());
+ //System.out.println("notify~~~~~~~~");
+ lock.notify();
+ }
+ }
+ if(screenImage != null){
+ image = screenImage;
+ FPScount++;
+ repaint();
+ }
+
+ } catch (Exception e) {
+
+ }
+ // decompress(imageByte);
+ }
+ }
+ }
+
+ class FPSCheckThread extends Thread {
+ public void run() {
+ while (true) {
+ try {
+ sleep(1000);
+ FPSlabel.setText("FPS : " + Integer.toString(FPScount));
+ // repaint();
+ // System.out.println("FPS : " + FPScount);
+ FPScount = 0;
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ }
+
+ class KeyboardThread extends Thread {
+ int result;
+ int keypress = 0;
+
+ public void run() {
+ LowLevelKeyboardProc rr = new LowLevelKeyboardProc() {
+
+ @Override
+ public LRESULT callback(int nCode, WPARAM wParam, KBDLLHOOKSTRUCT info) {
+ try {
+ System.out.println(info.vkCode);
+ if (info.vkCode == 21) {
+ System.out.println("한영");
+ if (keypress == 0) {
+ u32.keybd_event((byte) 0x15, (byte) 0, 0, 0);// 누름ffDDDddSS
+ u32.keybd_event((byte) 0x15, (byte) 00, (byte) 0x0002, 0);// 땜
+ keypress++;
+ } else {
+ keypress = 0;
+ }
+
+ }
+ if (nCode >= 0) {
+
+ switch (wParam.intValue()) {
+ case WinUser.WM_KEYUP:
+ keyboardOutputStream.writeInt(KEY_RELEASED);
+ keyboardOutputStream.writeInt(info.vkCode);
+ break;
+ case WinUser.WM_KEYDOWN:
+ keyboardOutputStream.writeInt(KEY_PRESSED);
+ keyboardOutputStream.writeInt(info.vkCode);
+ break;
+ case WinUser.WM_SYSKEYUP:
+ keyboardOutputStream.writeInt(KEY_RELEASED);
+ keyboardOutputStream.writeInt(info.vkCode);
+ break;
+ case WinUser.WM_SYSKEYDOWN:
+ keyboardOutputStream.writeInt(KEY_PRESSED);
+ keyboardOutputStream.writeInt(info.vkCode);
+ break;
+ }
+
+ }
+ } catch (Exception e) {
+ DebugMessage.printDebugMessage(e);
+ }
+
+ Pointer ptr = info.getPointer();
+
+ long peer = Pointer.nativeValue(ptr);
+
+ return lib.CallNextHookEx(hhk, nCode, wParam, new LPARAM(peer));
+ }
+ };
+ hhk = lib.SetWindowsHookEx(WinUser.WH_KEYBOARD_LL, rr, hMod, 0);
+ MSG msg = new MSG();
+ while ((result = lib.GetMessage(msg, null, 0, 0)) != 0) {
+ if (result == -1) {
+ System.err.println("error in get message");
+ break;
+ } else {
+ System.err.println("got message");
+ lib.TranslateMessage(msg);
+ lib.DispatchMessage(msg);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
+ }
+}
diff --git a/RemoteControl-Server/RemoteControl-Server.iml b/RemoteControl-Server/RemoteControl-Server.iml
new file mode 100644
index 0000000..787555e
--- /dev/null
+++ b/RemoteControl-Server/RemoteControl-Server.iml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/RemoteControl-Server/pom.xml b/RemoteControl-Server/pom.xml
new file mode 100644
index 0000000..11b581f
--- /dev/null
+++ b/RemoteControl-Server/pom.xml
@@ -0,0 +1,44 @@
+
+
+ 4.0.0
+
+ groupId
+ RemoteControl-Server
+ 1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 1.8
+
+
+
+
+
+
+
+ net.java.dev.jna
+ jna
+ 4.1.0
+
+
+
+ net.java.dev.jna
+ jna-platform
+ 4.1.0
+
+
+
+ org.xerial.snappy
+ snappy-java
+ 1.1.4
+
+
+
+
+
\ No newline at end of file
diff --git a/RemoteControlServer/src/DebugMessage.java b/RemoteControl-Server/src/main/java/DebugMessage.java
similarity index 95%
rename from RemoteControlServer/src/DebugMessage.java
rename to RemoteControl-Server/src/main/java/DebugMessage.java
index 8f013ce..e7a7cde 100644
--- a/RemoteControlServer/src/DebugMessage.java
+++ b/RemoteControl-Server/src/main/java/DebugMessage.java
@@ -1,11 +1,11 @@
-
-public class DebugMessage {
- public static void printDebugMessage(String message) {
- System.out.println(message);
- }
-
- public static void printDebugMessage(Exception e) {
- e.getStackTrace();
- System.out.println(e.getMessage());
- }
-}
+
+public class DebugMessage {
+ public static void printDebugMessage(String message) {
+ System.out.println(message);
+ }
+
+ public static void printDebugMessage(Exception e) {
+ e.getStackTrace();
+ System.out.println(e.getMessage());
+ }
+}
diff --git a/RemoteControlServer/src/JNAScreenShot.java b/RemoteControl-Server/src/main/java/JNAScreenShot.java
similarity index 92%
rename from RemoteControlServer/src/JNAScreenShot.java
rename to RemoteControl-Server/src/main/java/JNAScreenShot.java
index 5c0ae58..aa48c16 100644
--- a/RemoteControlServer/src/JNAScreenShot.java
+++ b/RemoteControl-Server/src/main/java/JNAScreenShot.java
@@ -1,159 +1,152 @@
-import java.awt.Rectangle;
-import java.awt.image.BufferedImage;
-import java.awt.image.ColorModel;
-import java.awt.image.DataBuffer;
-import java.awt.image.DataBufferInt;
-import java.awt.image.DataBufferUShort;
-import java.awt.image.DirectColorModel;
-import java.awt.image.Raster;
-import java.awt.image.WritableRaster;
-
-import com.sun.jna.Native;
-import com.sun.jna.platform.win32.WinDef.HBITMAP;
-import com.sun.jna.platform.win32.WinDef.HDC;
-import com.sun.jna.platform.win32.WinDef.HWND;
-import com.sun.jna.platform.win32.WinGDI.BITMAPINFO;
-import com.sun.jna.platform.win32.WinGDI.BITMAPINFOHEADER;
-import com.sun.jna.platform.win32.WinNT.HANDLE;
-import com.sun.jna.win32.W32APIOptions;
-
-public class JNAScreenShot {
-
- public static BufferedImage getScreenshot(Rectangle bounds) {
-
- HDC windowDC = GDI.GetDC(USER.GetDesktopWindow());
- HBITMAP outputBitmap =
- GDI.CreateCompatibleBitmap(windowDC,
- bounds.width, bounds.height);
- try {
- HDC blitDC = GDI.CreateCompatibleDC(windowDC);
- try {
- HANDLE oldBitmap =
- GDI.SelectObject(blitDC, outputBitmap);
- try {
- GDI.BitBlt(blitDC,
- 0, 0, bounds.width, bounds.height,
- windowDC,
- bounds.x, bounds.y,
- GDI32.SRCCOPY);
- } finally {
- GDI.SelectObject(blitDC, oldBitmap);
- }
- BITMAPINFO bi = new BITMAPINFO(40);
- bi.bmiHeader.biSize = 40;
- boolean ok =
- GDI.GetDIBits(blitDC, outputBitmap, 0, bounds.height,
- (byte[]) null, bi, 0);
- if (ok) {
- BITMAPINFOHEADER bih = bi.bmiHeader;
- bih.biHeight = - Math.abs(bih.biHeight);
- bi.bmiHeader.biCompression = 0;
- return bufferedImageFromBitmap(blitDC, outputBitmap, bi);
- } else {
- return null;
- }
- } finally {
- GDI.DeleteObject(blitDC);
- }
- } finally {
- GDI.DeleteObject(outputBitmap);
- }
- }
-
- private static BufferedImage bufferedImageFromBitmap(HDC blitDC, HBITMAP outputBitmap, BITMAPINFO bi) {
- BITMAPINFOHEADER bih = bi.bmiHeader;
- int height = Math.abs(bih.biHeight);
- final ColorModel cm;
- final DataBuffer buffer;
- final WritableRaster raster;
- int strideBits =
- (bih.biWidth * bih.biBitCount);
- int strideBytesAligned =
- (((strideBits - 1) | 0x1F) + 1) >> 3;
- final int strideElementsAligned;
- switch (bih.biBitCount) {
- case 16:
- strideElementsAligned = strideBytesAligned / 2;
- cm = new DirectColorModel(16, 0x7C00, 0x3E0, 0x1F);
- buffer =
- new DataBufferUShort(strideElementsAligned * height);
- raster =
- Raster.createPackedRaster(buffer,
- bih.biWidth, height,
- strideElementsAligned,
- ((DirectColorModel) cm).getMasks(),
- null);
- break;
- case 32:
- strideElementsAligned = strideBytesAligned / 4;
- cm = new DirectColorModel(32, 0xFF0000, 0xFF00, 0xFF);
- buffer =
- new DataBufferInt(strideElementsAligned * height);
- raster =
- Raster.createPackedRaster(buffer,
- bih.biWidth, height,
- strideElementsAligned,
- ((DirectColorModel) cm).getMasks(),
- null);
- break;
- default:
- throw new IllegalArgumentException("Unsupported bit count: " + bih.biBitCount);
- }
- final boolean ok;
- switch (buffer.getDataType()) {
- case DataBuffer.TYPE_INT:
- {
- int[] pixels = ((DataBufferInt) buffer).getData();
- ok = GDI.GetDIBits(blitDC, outputBitmap, 0, raster.getHeight(), pixels, bi, 0);
- }
- break;
- case DataBuffer.TYPE_USHORT:
- {
- short[] pixels = ((DataBufferUShort) buffer).getData();
- ok = GDI.GetDIBits(blitDC, outputBitmap, 0, raster.getHeight(), pixels, bi, 0);
- }
- break;
- default:
- throw new AssertionError("Unexpected buffer element type: " + buffer.getDataType());
- }
- if (ok) {
- return new BufferedImage(cm, raster, false, null);
- } else {
- return null;
- }
- }
-
- private static final User32 USER = User32.INSTANCE;
-
- private static final GDI32 GDI = GDI32.INSTANCE;
-
-}
-
-interface GDI32 extends com.sun.jna.platform.win32.GDI32 {
- GDI32 INSTANCE =
- (GDI32) Native.loadLibrary(GDI32.class);
- boolean BitBlt(HDC hdcDest,
- int nXDest,
- int nYDest,
- int nWidth,
- int nHeight,
- HDC hdcSrc,
- int nXSrc,
- int nYSrc,
- int dwRop);
- HDC GetDC(HWND hWnd);
- boolean GetDIBits(HDC dc, HBITMAP bmp, int startScan, int scanLines,
- byte[] pixels, BITMAPINFO bi, int usage);
- boolean GetDIBits(HDC dc, HBITMAP bmp, int startScan, int scanLines,
- short[] pixels, BITMAPINFO bi, int usage);
- boolean GetDIBits(HDC dc, HBITMAP bmp, int startScan, int scanLines,
- int[] pixels, BITMAPINFO bi, int usage);
- int SRCCOPY = 0xCC0020;
-}
-
-interface User32 extends com.sun.jna.platform.win32.User32 {
- User32 INSTANCE =
- (User32) Native.loadLibrary(User32.class,
- W32APIOptions.UNICODE_OPTIONS);
- HWND GetDesktopWindow();
+import com.sun.jna.Native;
+import com.sun.jna.platform.win32.WinDef.HBITMAP;
+import com.sun.jna.platform.win32.WinDef.HDC;
+import com.sun.jna.platform.win32.WinDef.HWND;
+import com.sun.jna.platform.win32.WinGDI.BITMAPINFO;
+import com.sun.jna.platform.win32.WinGDI.BITMAPINFOHEADER;
+import com.sun.jna.platform.win32.WinNT.HANDLE;
+import com.sun.jna.win32.W32APIOptions;
+
+import java.awt.*;
+import java.awt.image.*;
+
+public class JNAScreenShot {
+
+ public static BufferedImage getScreenshot(Rectangle bounds) {
+
+ HDC windowDC = GDI.GetDC(USER.GetDesktopWindow());
+ HBITMAP outputBitmap =
+ GDI.CreateCompatibleBitmap(windowDC,
+ bounds.width, bounds.height);
+ try {
+ HDC blitDC = GDI.CreateCompatibleDC(windowDC);
+ try {
+ HANDLE oldBitmap =
+ GDI.SelectObject(blitDC, outputBitmap);
+ try {
+ GDI.BitBlt(blitDC,
+ 0, 0, bounds.width, bounds.height,
+ windowDC,
+ bounds.x, bounds.y,
+ GDI32.SRCCOPY);
+ } finally {
+ GDI.SelectObject(blitDC, oldBitmap);
+ }
+ BITMAPINFO bi = new BITMAPINFO(40);
+ bi.bmiHeader.biSize = 40;
+ boolean ok =
+ GDI.GetDIBits(blitDC, outputBitmap, 0, bounds.height,
+ (byte[]) null, bi, 0);
+ if (ok) {
+ BITMAPINFOHEADER bih = bi.bmiHeader;
+ bih.biHeight = - Math.abs(bih.biHeight);
+ bi.bmiHeader.biCompression = 0;
+ return bufferedImageFromBitmap(blitDC, outputBitmap, bi);
+ } else {
+ return null;
+ }
+ } finally {
+ GDI.DeleteObject(blitDC);
+ }
+ } finally {
+ GDI.DeleteObject(outputBitmap);
+ }
+ }
+
+ private static BufferedImage bufferedImageFromBitmap(HDC blitDC, HBITMAP outputBitmap, BITMAPINFO bi) {
+ BITMAPINFOHEADER bih = bi.bmiHeader;
+ int height = Math.abs(bih.biHeight);
+ final ColorModel cm;
+ final DataBuffer buffer;
+ final WritableRaster raster;
+ int strideBits =
+ (bih.biWidth * bih.biBitCount);
+ int strideBytesAligned =
+ (((strideBits - 1) | 0x1F) + 1) >> 3;
+ final int strideElementsAligned;
+ switch (bih.biBitCount) {
+ case 16:
+ strideElementsAligned = strideBytesAligned / 2;
+ cm = new DirectColorModel(16, 0x7C00, 0x3E0, 0x1F);
+ buffer =
+ new DataBufferUShort(strideElementsAligned * height);
+ raster =
+ Raster.createPackedRaster(buffer,
+ bih.biWidth, height,
+ strideElementsAligned,
+ ((DirectColorModel) cm).getMasks(),
+ null);
+ break;
+ case 32:
+ strideElementsAligned = strideBytesAligned / 4;
+ cm = new DirectColorModel(32, 0xFF0000, 0xFF00, 0xFF);
+ buffer =
+ new DataBufferInt(strideElementsAligned * height);
+ raster =
+ Raster.createPackedRaster(buffer,
+ bih.biWidth, height,
+ strideElementsAligned,
+ ((DirectColorModel) cm).getMasks(),
+ null);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported bit count: " + bih.biBitCount);
+ }
+ final boolean ok;
+ switch (buffer.getDataType()) {
+ case DataBuffer.TYPE_INT:
+ {
+ int[] pixels = ((DataBufferInt) buffer).getData();
+ ok = GDI.GetDIBits(blitDC, outputBitmap, 0, raster.getHeight(), pixels, bi, 0);
+ }
+ break;
+ case DataBuffer.TYPE_USHORT:
+ {
+ short[] pixels = ((DataBufferUShort) buffer).getData();
+ ok = GDI.GetDIBits(blitDC, outputBitmap, 0, raster.getHeight(), pixels, bi, 0);
+ }
+ break;
+ default:
+ throw new AssertionError("Unexpected buffer element type: " + buffer.getDataType());
+ }
+ if (ok) {
+ return new BufferedImage(cm, raster, false, null);
+ } else {
+ return null;
+ }
+ }
+
+ private static final User32 USER = User32.INSTANCE;
+
+ private static final GDI32 GDI = GDI32.INSTANCE;
+
+}
+
+interface GDI32 extends com.sun.jna.platform.win32.GDI32 {
+ GDI32 INSTANCE =
+ (GDI32) Native.loadLibrary(GDI32.class);
+ boolean BitBlt(HDC hdcDest,
+ int nXDest,
+ int nYDest,
+ int nWidth,
+ int nHeight,
+ HDC hdcSrc,
+ int nXSrc,
+ int nYSrc,
+ int dwRop);
+ HDC GetDC(HWND hWnd);
+ boolean GetDIBits(HDC dc, HBITMAP bmp, int startScan, int scanLines,
+ byte[] pixels, BITMAPINFO bi, int usage);
+ boolean GetDIBits(HDC dc, HBITMAP bmp, int startScan, int scanLines,
+ short[] pixels, BITMAPINFO bi, int usage);
+ boolean GetDIBits(HDC dc, HBITMAP bmp, int startScan, int scanLines,
+ int[] pixels, BITMAPINFO bi, int usage);
+ int SRCCOPY = 0xCC0020;
+}
+
+interface User32 extends com.sun.jna.platform.win32.User32 {
+ User32 INSTANCE =
+ (User32) Native.loadLibrary(User32.class,
+ W32APIOptions.UNICODE_OPTIONS);
+ HWND GetDesktopWindow();
}
\ No newline at end of file
diff --git a/RemoteControlServer/src/NetworkScreenServer.java b/RemoteControl-Server/src/main/java/NetworkScreenServer.java
similarity index 89%
rename from RemoteControlServer/src/NetworkScreenServer.java
rename to RemoteControl-Server/src/main/java/NetworkScreenServer.java
index e933afb..3cd6c34 100644
--- a/RemoteControlServer/src/NetworkScreenServer.java
+++ b/RemoteControl-Server/src/main/java/NetworkScreenServer.java
@@ -1,509 +1,493 @@
-import java.awt.AWTException;
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.Image;
-import java.awt.Rectangle;
-import java.awt.Robot;
-import java.awt.Toolkit;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseEvent;
-import java.awt.image.BufferedImage;
-import java.awt.image.DataBufferByte;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.URL;
-import java.util.Vector;
-
-import javax.imageio.ImageIO;
-import javax.swing.ButtonGroup;
-import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JRadioButton;
-import javax.swing.JTextField;
-
-import org.xerial.snappy.Snappy;
-
-import com.sun.jna.Library;
-import com.sun.jna.Native;
-
-
-
-public class NetworkScreenServer extends JFrame {
- private static final long serialVersionUID = 1L;
- private final static int SERVER_PORT = 9999;
- private final static int SERVER_CURSOR_PORT = SERVER_PORT - 1;
- private final static int SERVER_KEBOARD_PORT = SERVER_PORT - 2;
- private DataOutputStream dataOutputStream;
- private Image cursor;
- private String myFont = "";
- private Rectangle rect;
- private MainPanel mainPanel = new MainPanel();
- private ServerSocket imageSeverSocket = null;
- private ServerSocket cursorServerSocket = null;
- private ServerSocket keyboardServerSocket = null;
- private Socket imageSocket = null;
- private Socket cursorSocket = null;
- private Socket keyboardSocket = null;
- private Robot robot;
- private int screenWidth, screenHeight;
- private Boolean isRunning = false;
- private Thread imgThread;
- private static int new_Width = 1920;
- private static int new_Height = 1080;
- private JButton startBtn;
- private JButton stopBtn;
- private JTextField widthTextfield;
- private JTextField heightTextfield;
- private JRadioButton compressTrueRBtn;
- private JRadioButton compressFalseRBtn;
- private JLabel widthLabel;
- private JLabel heightLabel;
- private JLabel compressLabel;
- private URL cursorURL = getClass().getClassLoader().getResource("cursor.gif");
- private Boolean isCompress = true;
- private final int MOUSE_MOVE = 1;
- private final int MOUSE_PRESSD = 2;
- private final int MOUSE_RELEASED = 3;
- private final int MOUSE_DOWN_WHEEL = 4;
- private final int MOUSE_UP_WHEEL = 5;
- private final int KEY_PRESSED = 6;
- private final int KEY_RELEASED = 7;
- int count = 0, count2 = 0;
- private User32jna u32 = User32jna.INSTANCE;
- private Vector imgvec = new Vector<>();
-
- public NetworkScreenServer() {
- setTitle("-");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setLayout(null);
- setContentPane(mainPanel);
- setSize(490, 160);
- setVisible(true);
- setResizable(false);
-
- addKeyListener(new KeyAdapter() {
- @Override
- public void keyTyped(KeyEvent e) {
- System.out.println("type" + e.getKeyCode() + " " + e.getKeyChar() + " " + e.getID() + " "
- + e.getModifiers() + " " + e.getKeyLocation() + " " + e.getExtendedKeyCode());
- }
-
- @Override
- public void keyPressed(KeyEvent e) {
- System.out.println("pressed" + e.getKeyCode() + " " + e.getKeyChar() + " " + e.getID() + " "
- + e.getModifiers() + " " + e.getKeyLocation() + " " + e.getExtendedKeyCode());
- super.keyPressed(e);
- }
-
- @Override
- public void keyReleased(KeyEvent e) {
- System.out.println("released" + e.getKeyCode() + " " + e.getKeyChar() + " " + e.getID() + " "
- + e.getModifiers() + " " + e.getKeyLocation() + " " + e.getExtendedKeyCode());
- if (e.getKeyCode() == 0) {
- if (count >= 1) {
- count = 0;
- return;
- }
- // System.out.println(t.getLocale().toString() + " " +
- // t.getLocale().getCountry() + " " +
- // t.getLocale().getDisplayCountry());
- System.out.println("ee");
- count = 1;
- u32.keybd_event((byte) 0x15, (byte) 0, 0, 0);// ffDDDddSS
- u32.keybd_event((byte) 0x15, (byte) 00, (byte) 0x0002, 0);//
- //
- }
- }
- });
- widthTextfield.requestFocus();
- }
-
- public interface User32jna extends Library {
- User32jna INSTANCE = (User32jna) Native.loadLibrary("user32.dll", User32jna.class);
-
- // User32jna INSTANCE = (User32jna)
- // Native.loadLibrary("user32.dll",User32jna.class);
- public void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
- }
-
- /*
- * User32jna u32 = User32jna.INSTANCE;
- */
-
- class MainPanel extends JPanel implements Runnable {
-
- private static final long serialVersionUID = 1L;
-
- public MainPanel() {
- setLayout(null);
-
- startBtn = new JButton("Start");
- stopBtn = new JButton("Stop");
- widthTextfield = new JTextField(Integer.toString(new_Width), 5);
- heightTextfield = new JTextField(Integer.toString(new_Height), 5);
- widthLabel = new JLabel("width");
- heightLabel = new JLabel("height");
- compressLabel = new JLabel("   Image
Compress");
- compressTrueRBtn = new JRadioButton("True");
- compressFalseRBtn = new JRadioButton("False");
-
- startBtn.setBounds(0, 0, 150, 130);
- stopBtn.setBounds(150, 0, 150, 130);
- widthLabel.setBounds(327, 8, 50, 15);
- widthTextfield.setBounds(300, 30, 90, 35);
- heightLabel.setBounds(325, 70, 50, 15);
- heightTextfield.setBounds(300, 90, 90, 35);
- compressLabel.setBounds(405, -10, 100, 50);
- compressTrueRBtn.setBounds(390, 30, 80, 30);
- compressFalseRBtn.setBounds(390, 90, 80, 30);
-
- ButtonGroup group = new ButtonGroup();
- group.add(compressTrueRBtn);
- group.add(compressFalseRBtn);
-
- widthLabel.setFont(new Font(myFont, Font.PLAIN, 15));
- heightLabel.setFont(new Font(myFont, Font.PLAIN, 15));
-
- compressLabel.setFont(new Font(myFont, Font.PLAIN, 10));
- startBtn.setFont(new Font(myFont, Font.PLAIN, 20));
- stopBtn.setFont(new Font(myFont, Font.PLAIN, 20));
- compressTrueRBtn.setFont(new Font(myFont, Font.PLAIN, 20));
- compressFalseRBtn.setFont(new Font(myFont, Font.PLAIN, 20));
-
- compressTrueRBtn.setSelected(true);
-
- add(startBtn);
- add(stopBtn);
- add(widthLabel);
- add(widthTextfield);
- add(heightLabel);
- add(heightTextfield);
- add(compressLabel);
- add(compressTrueRBtn);
- add(compressFalseRBtn);
- stopBtn.setEnabled(false);
- startBtn.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- if (isRunning)
- return;
- try {
- new_Height = Integer.parseInt(heightTextfield.getText());
- new_Width = Integer.parseInt(widthTextfield.getText());
- } catch (Exception e1) {
- return;
- }
- heightTextfield.setEditable(false);
- widthTextfield.setEditable(false);
- isRunning = true;
- startBtn.setEnabled(false);
- stopBtn.setEnabled(true);
- if (compressTrueRBtn.isSelected()) {
- isCompress = true;
- } else if (compressFalseRBtn.isSelected()) {
- isCompress = false;
- }
- compressTrueRBtn.setEnabled(false);
- compressFalseRBtn.setEnabled(false);
-
- imgThread = new Thread(mainPanel);
- CursorThread cursorThread = new CursorThread();
- KeyBoardThread keyBoardThread = new KeyBoardThread();
- imgThread.start();
- cursorThread.start();
- keyBoardThread.start();
-
- }
- });
- stopBtn.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- if (!isRunning)
- return;
- heightTextfield.setEditable(true);
- widthTextfield.setEditable(true);
- isRunning = false;
- ServerSocketCloseThread closeThread = new ServerSocketCloseThread();
- closeThread.start();
- // imgThread.interrupt();
- stopBtn.setEnabled(false);
- startBtn.setEnabled(true);
- compressTrueRBtn.setEnabled(true);
- compressFalseRBtn.setEnabled(true);
-
- }
- });
- widthTextfield.transferFocus();
- }
-
- public void run() {
-
- try {
- robot = new Robot();
- screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
- screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
- rect = new Rectangle(0, 0, screenWidth, screenHeight);
- System.out.println("");
- imageSeverSocket = new ServerSocket(SERVER_PORT);// ImageSERVER
-
- imageSocket = imageSeverSocket.accept();
- imageSocket.setTcpNoDelay(true);
- dataOutputStream = new DataOutputStream(imageSocket.getOutputStream());
- dataOutputStream.writeInt(screenWidth);
- dataOutputStream.writeInt(screenHeight);
- dataOutputStream.writeInt(new_Width);
- dataOutputStream.writeInt(new_Height);
- dataOutputStream.writeBoolean(isCompress);
- cursor = ImageIO.read(cursorURL);
- } catch (Exception e) {
-
- }
- ImgDoubleBufferTh th = new ImgDoubleBufferTh();
- th.start();
-
- //new ImgDoubleBufferTh().start();
-
- // ImageIO.setUseCache(false);// little more spped
-
- // imgvec.add(getScaledImage(robot.createScreenCapture(rectangle),screenWidth,screenHeight,BufferedImage.TYPE_3BYTE_BGR));
- // Image cursor = ImageIO.read(new
- // File("c:\\Test\\cursor.gif"));
-
- // long starttime,estimatedTime;
- int index = 0;
- Runtime runtime = Runtime.getRuntime();
- while (isRunning) {
- try {
-
- // screenImage =
- // JNAScreenShot.getScreenshot(rectangle);//robot.createScreenCapture(rectangle);
- // if (img[index] != null) {
- // screenImage = img[index];//
- // robot.createScreenCapture(rectangle);
-
- //screenImage =imgvec.get(0); //robot.createScreenCapture(rect);//
- byte[] imageByte = imgvec.get(0);
- if(imgvec.size() == 3){
- synchronized (th) {
- th.notify();
- }
- }
-
-
-
- /*
- * int mouseX = MouseInfo.getPointerInfo().getLocation().x;
- * int mouseY = MouseInfo.getPointerInfo().getLocation().y;
- *
- * screenImage.getGraphics().drawImage(cursor, mouseX,
- * mouseY, 30, 30, null);
- */
-
-
-
-
- if (isCompress) {
-
- //byte[] compressImageByte = compress(imageByte);// 6MB->480KB
- // System.out.println("compress : " +
- // (double)compressImageByte.length/1024 + "kb");
- dataOutputStream.writeInt(imageByte.length);
- dataOutputStream.write(imageByte);
-
- // System.out.println(imageByte.length);
- dataOutputStream.flush();
- } else {
- dataOutputStream.writeInt(imageByte.length);
- dataOutputStream.write(imageByte);
- // System.out.println(imageByte.length);
-
- dataOutputStream.flush();
- }
- //}
- } catch (Exception e) {
-
- }
- if (runtime.totalMemory() / 1024 / 1024 > 500)
- System.gc();
- if (imgvec.size() > 1) {
- /* new Thread(){
- public void run(){ */
- //System.out.println(imgvec.size());
- imgvec.remove(0);
- index++;
- if(index == 30){
- System.out.println("");
- index=0;
- System.gc();
- }
- /* }
- }.start();*/
- }
-
-
- // Thread.sleep(1000);
- }
-
- }
-
- }
-
- class ImgDoubleBufferTh extends Thread {
- BufferedImage bufferimage;
- Robot robot = null;
-
- synchronized public void run() {
- try {
- robot = new Robot();
- } catch (AWTException e) {
- }
- while (true) {
-
- bufferimage = robot.createScreenCapture(rect);
- bufferimage = getScaledImage(bufferimage, new_Width, new_Height, BufferedImage.TYPE_3BYTE_BGR);
- byte[] imageByte = ((DataBufferByte) bufferimage.getRaster().getDataBuffer()).getData();
- try {
- imgvec.addElement(compress(imageByte));
- } catch (IOException e) {
- e.printStackTrace();
- }
- //System.out.println(imgvec.size());
- if(imgvec.size()>5)
- try {
- System.out.println("wait");
- wait();
- } catch (InterruptedException e) {
-
- }
- }
-
- }
- }
-
- public static byte[] compress(byte[] data) throws IOException {
- byte[] output = Snappy.compress(data);
-
- return output;
- }
-
- public BufferedImage getScaledImage(BufferedImage myImage, int width, int height, int type) {
- BufferedImage background = new BufferedImage(width, height, type);
- Graphics2D g = background.createGraphics();
- g.setColor(Color.WHITE);
- g.drawImage(myImage, 0, 0, width, height, null);
- g.dispose();
- return background;
- }
-
- class ServerSocketCloseThread extends Thread {
- public void run() {
- if (!imageSeverSocket.isClosed() || !cursorServerSocket.isClosed() || keyboardServerSocket.isClosed()) {
- try {
- imageSeverSocket.close();
- cursorServerSocket.close();
- keyboardServerSocket.close();
- } catch (IOException e) {
- DebugMessage.printDebugMessage(e);
- }
- }
- }
- }
-
- class KeyBoardThread extends Thread {
- public void run() {
- try {
- keyboardServerSocket = new ServerSocket(SERVER_KEBOARD_PORT);
- keyboardSocket = keyboardServerSocket.accept();
- DataInputStream dataInputStream = new DataInputStream(keyboardSocket.getInputStream());
- while (true) {
- int keyboardState = dataInputStream.readInt();
- if (keyboardState == KEY_PRESSED) {// KEYBOARD PRESSED
- int keyCode = dataInputStream.readInt();
- // System.out.println(keyCode + "");
- u32.keybd_event((byte) keyCode, (byte) 0, 0, 0);// ffDDDddSS
- // robot.keyPress(keyCode);
- } else if (keyboardState == KEY_RELEASED) {
- int keyCode = dataInputStream.readInt();
- // System.out.println(keyCode + "");
- u32.keybd_event((byte) keyCode, (byte) 00, (byte) 0x0002, 0);//
- // robot.keyRelease(keyCode);
- }
- yield();
- }
- } catch (Exception e) {
-
- }
- }
- }
-
- class CursorThread extends Thread {
- public void run() {
- try {
- System.out.println("ѱ");
- cursorServerSocket = new ServerSocket(SERVER_CURSOR_PORT);// cursorSERVER
- cursorSocket = cursorServerSocket.accept();
- System.out.println("Ŀ Դ");
- DataInputStream dataInputStream = new DataInputStream(cursorSocket.getInputStream());
- int mouseX = 0;
- int mouseY = 0;
- while (isRunning) {
- int mouseState = dataInputStream.readInt();// mouse,Keyboard
- // state
- if (mouseState == MOUSE_MOVE) {// move
- mouseX = dataInputStream.readInt();
- mouseY = dataInputStream.readInt();
-
- robot.mouseMove(mouseX, mouseY);
- } else if (mouseState == MOUSE_PRESSD) { // pressed
- int mouseButton = dataInputStream.readInt();
- robot.mouseMove(mouseX, mouseY);
- if (mouseButton == 1) {
- robot.mousePress(MouseEvent.BUTTON1_MASK);
- } else if (mouseButton == 2) {
- robot.mousePress(MouseEvent.BUTTON2_MASK);
- } else if (mouseButton == 3) {
- robot.mousePress(MouseEvent.BUTTON3_MASK);
- }
- } else if (mouseState == MOUSE_RELEASED) {// released
- int mouseButton = dataInputStream.readInt();
- robot.mouseMove(mouseX, mouseY);
- if (mouseButton == 1) {
- robot.mouseRelease(MouseEvent.BUTTON1_MASK);
- } else if (mouseButton == 2) {
- robot.mouseRelease(MouseEvent.BUTTON2_MASK);
- } else if (mouseButton == 3) {
- robot.mouseRelease(MouseEvent.BUTTON3_MASK);
- }
- } else if (mouseState == MOUSE_DOWN_WHEEL) {// MOUSE DOWN
- // WHEEL
- robot.mouseWheel(-3);
- } else if (mouseState == MOUSE_UP_WHEEL) {// MOUSE UP WHEEL
- robot.mouseWheel(3);
- }
- yield();
- }
-
- } catch (Exception e) {
-
- }
-
- }
- }
-
- public static void main(String[] args) {
- new NetworkScreenServer();
- }
-
-}
+import com.sun.jna.Library;
+import com.sun.jna.Native;
+import org.xerial.snappy.Snappy;
+
+import javax.imageio.ImageIO;
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBufferByte;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.URL;
+import java.util.Vector;
+
+
+public class NetworkScreenServer extends JFrame {
+ private final static int SERVER_PORT = 9999;
+ private final static int SERVER_CURSOR_PORT = SERVER_PORT - 1;
+ private final static int SERVER_KEBOARD_PORT = SERVER_PORT - 2;
+ private DataOutputStream dataOutputStream;
+ private ObjectOutputStream objectOutputStream;
+ private Image cursor;
+ private String myFont = "�������";
+ private BufferedImage screenImage;
+ private Rectangle rect;
+ private MainPanel mainPanel = new MainPanel();
+ private ServerSocket imageSeverSocket = null;
+ private ServerSocket cursorServerSocket = null;
+ private ServerSocket keyboardServerSocket = null;
+ private Socket imageSocket = null;
+ private Socket cursorSocket = null;
+ private Socket keyboardSocket = null;
+ private Robot robot;
+ private int screenWidth, screenHeight;
+ private Boolean isRunning = false;
+ private Thread imgThread;
+ private static int new_Width = 1920;
+ private static int new_Height = 1080;
+ private JButton startBtn;
+ private JButton stopBtn;
+ private JTextField widthTextfield;
+ private JTextField heightTextfield;
+ private JRadioButton compressTrueRBtn;
+ private JRadioButton compressFalseRBtn;
+ private JLabel widthLabel;
+ private JLabel heightLabel;
+ private JLabel compressLabel;
+ private URL cursorURL = getClass().getClassLoader().getResource("cursor.gif");
+ private Boolean isCompress = true;
+ private JFrame fff = this;
+ private final int MOUSE_MOVE = 1;
+ private final int MOUSE_PRESSD = 2;
+ private final int MOUSE_RELEASED = 3;
+ private final int MOUSE_DOWN_WHEEL = 4;
+ private final int MOUSE_UP_WHEEL = 5;
+ private final int KEY_PRESSED = 6;
+ private final int KEY_RELEASED = 7;
+ private final int KEY_CHANGE_LANGUAGE = 8;
+ int count = 0, count2 = 0;
+ private User32jna u32 = User32jna.INSTANCE;
+ private int buffersize = 1;
+ private BufferedImage[] img = new BufferedImage[buffersize];
+ private Vector imgvec = new Vector<>();
+
+ public NetworkScreenServer() {
+ setTitle("원격지원 대상 컴퓨터용");
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ setLayout(null);
+ setContentPane(mainPanel);
+ setSize(490, 160);
+ setVisible(true);
+ setResizable(false);
+
+ addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyTyped(KeyEvent e) {
+ System.out.println("type" + e.getKeyCode() + " " + e.getKeyChar() + " " + e.getID() + " "
+ + e.getModifiers() + " " + e.getKeyLocation() + " " + e.getExtendedKeyCode());
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ System.out.println("pressed" + e.getKeyCode() + " " + e.getKeyChar() + " " + e.getID() + " "
+ + e.getModifiers() + " " + e.getKeyLocation() + " " + e.getExtendedKeyCode());
+ super.keyPressed(e);
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ System.out.println("released" + e.getKeyCode() + " " + e.getKeyChar() + " " + e.getID() + " "
+ + e.getModifiers() + " " + e.getKeyLocation() + " " + e.getExtendedKeyCode());
+ if (e.getKeyCode() == 0) {
+ if (count >= 1) {
+ count = 0;
+ return;
+ }
+ // System.out.println(t.getLocale().toString() + " " +
+ // t.getLocale().getCountry() + " " +
+ // t.getLocale().getDisplayCountry());
+ System.out.println("ee");
+ count = 1;
+ u32.keybd_event((byte) 0x15, (byte) 0, 0, 0);// ����ffDDDddSS
+ u32.keybd_event((byte) 0x15, (byte) 00, (byte) 0x0002, 0);// ����
+ // ����
+ }
+ }
+ });
+ widthTextfield.requestFocus();
+ }
+
+ public interface User32jna extends Library {
+ User32jna INSTANCE = (User32jna) Native.loadLibrary("user32.dll", User32jna.class);
+
+ // User32jna INSTANCE = (User32jna)
+ // Native.loadLibrary("user32.dll",User32jna.class);
+ public void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
+ }
+
+ /*
+ * User32jna u32 = User32jna.INSTANCE;
+ */
+
+ class MainPanel extends JPanel implements Runnable {
+
+ public MainPanel() {
+ setLayout(null);
+
+ startBtn = new JButton("Start");
+ stopBtn = new JButton("Stop");
+ widthTextfield = new JTextField(Integer.toString(new_Width), 5);
+ heightTextfield = new JTextField(Integer.toString(new_Height), 5);
+ widthLabel = new JLabel("width");
+ heightLabel = new JLabel("height");
+ compressLabel = new JLabel("   Image
Compress");
+ compressTrueRBtn = new JRadioButton("True");
+ compressFalseRBtn = new JRadioButton("False");
+
+ startBtn.setBounds(0, 0, 150, 130);
+ stopBtn.setBounds(150, 0, 150, 130);
+ widthLabel.setBounds(327, 8, 50, 15);
+ widthTextfield.setBounds(300, 30, 90, 35);
+ heightLabel.setBounds(325, 70, 50, 15);
+ heightTextfield.setBounds(300, 90, 90, 35);
+ compressLabel.setBounds(405, -10, 100, 50);
+ compressTrueRBtn.setBounds(390, 30, 80, 30);
+ compressFalseRBtn.setBounds(390, 90, 80, 30);
+
+ ButtonGroup group = new ButtonGroup();
+ group.add(compressTrueRBtn);
+ group.add(compressFalseRBtn);
+
+ widthLabel.setFont(new Font(myFont, Font.PLAIN, 15));
+ heightLabel.setFont(new Font(myFont, Font.PLAIN, 15));
+
+ compressLabel.setFont(new Font(myFont, Font.PLAIN, 10));
+ startBtn.setFont(new Font(myFont, Font.PLAIN, 20));
+ stopBtn.setFont(new Font(myFont, Font.PLAIN, 20));
+ compressTrueRBtn.setFont(new Font(myFont, Font.PLAIN, 20));
+ compressFalseRBtn.setFont(new Font(myFont, Font.PLAIN, 20));
+
+ compressTrueRBtn.setSelected(true);
+
+ add(startBtn);
+ add(stopBtn);
+ add(widthLabel);
+ add(widthTextfield);
+ add(heightLabel);
+ add(heightTextfield);
+ add(compressLabel);
+ add(compressTrueRBtn);
+ add(compressFalseRBtn);
+ stopBtn.setEnabled(false);
+ startBtn.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (isRunning)
+ return;
+ try {
+ new_Height = Integer.parseInt(heightTextfield.getText());
+ new_Width = Integer.parseInt(widthTextfield.getText());
+ } catch (Exception e1) {
+ return;
+ }
+ heightTextfield.setEditable(false);
+ widthTextfield.setEditable(false);
+ isRunning = true;
+ startBtn.setEnabled(false);
+ stopBtn.setEnabled(true);
+ if (compressTrueRBtn.isSelected()) {
+ isCompress = true;
+ } else if (compressFalseRBtn.isSelected()) {
+ isCompress = false;
+ }
+ compressTrueRBtn.setEnabled(false);
+ compressFalseRBtn.setEnabled(false);
+
+ imgThread = new Thread(mainPanel);
+ CursorThread cursorThread = new CursorThread();
+ KeyBoardThread keyBoardThread = new KeyBoardThread();
+ imgThread.start();
+ cursorThread.start();
+ keyBoardThread.start();
+
+ }
+ });
+ stopBtn.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (!isRunning)
+ return;
+ heightTextfield.setEditable(true);
+ widthTextfield.setEditable(true);
+ isRunning = false;
+ ServerSocketCloseThread closeThread = new ServerSocketCloseThread();
+ closeThread.start();
+ // imgThread.interrupt();
+ stopBtn.setEnabled(false);
+ startBtn.setEnabled(true);
+ compressTrueRBtn.setEnabled(true);
+ compressFalseRBtn.setEnabled(true);
+
+ }
+ });
+ widthTextfield.transferFocus();
+ }
+
+ public void run() {
+
+ try {
+ robot = new Robot();
+ screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
+ screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
+ rect = new Rectangle(0, 0, screenWidth, screenHeight);
+ System.out.println("��������");
+ imageSeverSocket = new ServerSocket(SERVER_PORT);// ImageSERVER
+
+ imageSocket = imageSeverSocket.accept();
+ imageSocket.setTcpNoDelay(true);
+ dataOutputStream = new DataOutputStream(imageSocket.getOutputStream());
+ objectOutputStream = new ObjectOutputStream(imageSocket.getOutputStream());
+ dataOutputStream.writeInt(screenWidth);
+ dataOutputStream.writeInt(screenHeight);
+ dataOutputStream.writeInt(new_Width);
+ dataOutputStream.writeInt(new_Height);
+ dataOutputStream.writeBoolean(isCompress);
+ cursor = ImageIO.read(cursorURL);
+ } catch (Exception e) {
+
+ }
+ ImgDoubleBufferTh th = new ImgDoubleBufferTh();
+ th.start();
+
+ //new ImgDoubleBufferTh().start();
+
+ // ImageIO.setUseCache(false);// little more spped
+
+ // imgvec.add(getScaledImage(robot.createScreenCapture(rectangle),screenWidth,screenHeight,BufferedImage.TYPE_3BYTE_BGR));
+ // Image cursor = ImageIO.read(new
+ // File("c:\\Test\\cursor.gif"));
+
+ // long starttime,estimatedTime;
+ int index = 0;
+ Runtime runtime = Runtime.getRuntime();
+ while (isRunning) {
+ try {
+
+ // screenImage =
+ // JNAScreenShot.getScreenshot(rectangle);//robot.createScreenCapture(rectangle);
+ // if (img[index] != null) {
+ // screenImage = img[index];//
+ // robot.createScreenCapture(rectangle);
+
+ //screenImage =imgvec.get(0); //robot.createScreenCapture(rect);//
+ byte[] imageByte = imgvec.get(0);
+ if(imgvec.size() == 3){
+ synchronized (th) {
+ th.notify();
+ }
+ }
+
+
+
+ /*
+ * int mouseX = MouseInfo.getPointerInfo().getLocation().x;
+ * int mouseY = MouseInfo.getPointerInfo().getLocation().y;
+ *
+ * screenImage.getGraphics().drawImage(cursor, mouseX,
+ * mouseY, 30, 30, null);
+ */
+
+
+
+
+ if (isCompress) {
+
+ //byte[] compressImageByte = compress(imageByte);// 6MB->480KB����
+ // System.out.println("compress : " +
+ // (double)compressImageByte.length/1024 + "kb");
+ dataOutputStream.writeInt(imageByte.length);
+ dataOutputStream.write(imageByte);
+
+ // System.out.println(imageByte.length);
+ dataOutputStream.flush();
+ } else {
+ dataOutputStream.writeInt(imageByte.length);
+ dataOutputStream.write(imageByte);
+ // System.out.println(imageByte.length);
+
+ dataOutputStream.flush();
+ }
+ //}
+ } catch (Exception e) {
+
+ }
+ if (runtime.totalMemory() / 1024 / 1024 > 500)
+ System.gc();
+ if (imgvec.size() > 1) {
+ /* new Thread(){
+ public void run(){ */
+ //System.out.println(imgvec.size());
+ imgvec.remove(0);
+ index++;
+ if(index == 30){
+ System.out.println("������");
+ index=0;
+ System.gc();
+ }
+ /* }
+ }.start();*/
+ }
+
+
+ // Thread.sleep(1000);
+ }
+
+ }
+
+ }
+
+ class ImgDoubleBufferTh extends Thread {
+ BufferedImage bufferimage;
+ Robot robot = null;
+
+ synchronized public void run() {
+ try {
+ robot = new Robot();
+ } catch (AWTException e) {
+ }
+ while (true) {
+
+ bufferimage = robot.createScreenCapture(rect);
+ bufferimage = getScaledImage(bufferimage, new_Width, new_Height, BufferedImage.TYPE_3BYTE_BGR);
+ byte[] imageByte = ((DataBufferByte) bufferimage.getRaster().getDataBuffer()).getData();
+ try {
+ imgvec.addElement(compress(imageByte));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ //System.out.println(imgvec.size());
+ if(imgvec.size()>5)
+ try {
+ System.out.println("wait");
+ wait();
+ } catch (InterruptedException e) {
+
+ }
+ }
+
+ }
+ }
+
+ public static byte[] compress(byte[] data) throws IOException {
+ byte[] output = Snappy.compress(data);
+
+ return output;
+ }
+
+ public BufferedImage getScaledImage(BufferedImage myImage, int width, int height, int type) {
+ BufferedImage background = new BufferedImage(width, height, type);
+ Graphics2D g = background.createGraphics();
+ g.setColor(Color.WHITE);
+ g.drawImage(myImage, 0, 0, width, height, null);
+ g.dispose();
+ return background;
+ }
+
+ class ServerSocketCloseThread extends Thread {
+ public void run() {
+ if (!imageSeverSocket.isClosed() || !cursorServerSocket.isClosed() || keyboardServerSocket.isClosed()) {
+ try {
+ imageSeverSocket.close();
+ cursorServerSocket.close();
+ keyboardServerSocket.close();
+ } catch (IOException e) {
+ DebugMessage.printDebugMessage(e);
+ }
+ }
+ }
+ }
+
+ class KeyBoardThread extends Thread {
+ public void run() {
+ try {
+ keyboardServerSocket = new ServerSocket(SERVER_KEBOARD_PORT);
+ keyboardSocket = keyboardServerSocket.accept();
+ DataInputStream dataInputStream = new DataInputStream(keyboardSocket.getInputStream());
+ while (true) {
+ int keyboardState = dataInputStream.readInt();
+ if (keyboardState == KEY_PRESSED) {// KEYBOARD PRESSED
+ int keyCode = dataInputStream.readInt();
+ // System.out.println(keyCode + "����");
+ u32.keybd_event((byte) keyCode, (byte) 0, 0, 0);// ����ffDDDddSS
+ // robot.keyPress(keyCode);
+ } else if (keyboardState == KEY_RELEASED) {
+ int keyCode = dataInputStream.readInt();
+ // System.out.println(keyCode + "����");
+ u32.keybd_event((byte) keyCode, (byte) 00, (byte) 0x0002, 0);// ��
+ // robot.keyRelease(keyCode);
+ }
+ yield();
+ }
+ } catch (Exception e) {
+
+ }
+ }
+ }
+
+ class CursorThread extends Thread {
+ public void run() {
+ try {
+ System.out.println("�ѱ�");
+ cursorServerSocket = new ServerSocket(SERVER_CURSOR_PORT);// cursorSERVER
+ cursorSocket = cursorServerSocket.accept();
+ System.out.println("Ŀ�� ���� ���Դ�");
+ DataInputStream dataInputStream = new DataInputStream(cursorSocket.getInputStream());
+ int mouseX = 0;
+ int mouseY = 0;
+ while (isRunning) {
+ int mouseState = dataInputStream.readInt();// mouse,Keyboard
+ // state
+ if (mouseState == MOUSE_MOVE) {// move
+ mouseX = dataInputStream.readInt();
+ mouseY = dataInputStream.readInt();
+
+ robot.mouseMove(mouseX, mouseY);
+ } else if (mouseState == MOUSE_PRESSD) { // pressed
+ int mouseButton = dataInputStream.readInt();
+ robot.mouseMove(mouseX, mouseY);
+ if (mouseButton == 1) {
+ robot.mousePress(MouseEvent.BUTTON1_MASK);
+ } else if (mouseButton == 2) {
+ robot.mousePress(MouseEvent.BUTTON2_MASK);
+ } else if (mouseButton == 3) {
+ robot.mousePress(MouseEvent.BUTTON3_MASK);
+ }
+ } else if (mouseState == MOUSE_RELEASED) {// released
+ int mouseButton = dataInputStream.readInt();
+ robot.mouseMove(mouseX, mouseY);
+ if (mouseButton == 1) {
+ robot.mouseRelease(MouseEvent.BUTTON1_MASK);
+ } else if (mouseButton == 2) {
+ robot.mouseRelease(MouseEvent.BUTTON2_MASK);
+ } else if (mouseButton == 3) {
+ robot.mouseRelease(MouseEvent.BUTTON3_MASK);
+ }
+ } else if (mouseState == MOUSE_DOWN_WHEEL) {// MOUSE DOWN
+ // WHEEL
+ robot.mouseWheel(-3);
+ } else if (mouseState == MOUSE_UP_WHEEL) {// MOUSE UP WHEEL
+ robot.mouseWheel(3);
+ }
+ yield();
+ }
+
+ } catch (Exception e) {
+
+ }
+
+ }
+ }
+
+ public static void main(String[] args) {
+ new NetworkScreenServer();
+ }
+
+}
diff --git a/RemoteControlClient/.classpath b/RemoteControlClient/.classpath
deleted file mode 100644
index 4a683fb..0000000
--- a/RemoteControlClient/.classpath
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/RemoteControlClient/.gitignore b/RemoteControlClient/.gitignore
deleted file mode 100644
index b83d222..0000000
--- a/RemoteControlClient/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/target/
diff --git a/RemoteControlClient/.project b/RemoteControlClient/.project
deleted file mode 100644
index ede27a1..0000000
--- a/RemoteControlClient/.project
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
- RemoteControlClient
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- org.eclipse.m2e.core.maven2Builder
-
-
-
-
-
- org.eclipse.m2e.core.maven2Nature
- org.eclipse.jdt.core.javanature
-
-
diff --git a/RemoteControlClient/.settings/org.eclipse.jdt.core.prefs b/RemoteControlClient/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index e24b722..0000000
--- a/RemoteControlClient/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,13 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.8
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.release=disabled
-org.eclipse.jdt.core.compiler.source=1.8
diff --git a/RemoteControlClient/.settings/org.eclipse.m2e.core.prefs b/RemoteControlClient/.settings/org.eclipse.m2e.core.prefs
deleted file mode 100644
index f897a7f..0000000
--- a/RemoteControlClient/.settings/org.eclipse.m2e.core.prefs
+++ /dev/null
@@ -1,4 +0,0 @@
-activeProfiles=
-eclipse.preferences.version=1
-resolveWorkspaceProjects=true
-version=1
diff --git a/RemoteControlClient/bin/DebugMessage.class b/RemoteControlClient/bin/DebugMessage.class
deleted file mode 100644
index 463ba44..0000000
Binary files a/RemoteControlClient/bin/DebugMessage.class and /dev/null differ
diff --git a/RemoteControlClient/bin/NetworkScreenClient$1.class b/RemoteControlClient/bin/NetworkScreenClient$1.class
deleted file mode 100644
index 0b5ab47..0000000
Binary files a/RemoteControlClient/bin/NetworkScreenClient$1.class and /dev/null differ
diff --git a/RemoteControlClient/bin/NetworkScreenClient$2.class b/RemoteControlClient/bin/NetworkScreenClient$2.class
deleted file mode 100644
index fdd9a4a..0000000
Binary files a/RemoteControlClient/bin/NetworkScreenClient$2.class and /dev/null differ
diff --git a/RemoteControlClient/bin/NetworkScreenClient$3.class b/RemoteControlClient/bin/NetworkScreenClient$3.class
deleted file mode 100644
index be79bf1..0000000
Binary files a/RemoteControlClient/bin/NetworkScreenClient$3.class and /dev/null differ
diff --git a/RemoteControlClient/bin/NetworkScreenClient$ControlPanel$1.class b/RemoteControlClient/bin/NetworkScreenClient$ControlPanel$1.class
deleted file mode 100644
index 550eda9..0000000
Binary files a/RemoteControlClient/bin/NetworkScreenClient$ControlPanel$1.class and /dev/null differ
diff --git a/RemoteControlClient/bin/NetworkScreenClient$ControlPanel$2.class b/RemoteControlClient/bin/NetworkScreenClient$ControlPanel$2.class
deleted file mode 100644
index 71143ad..0000000
Binary files a/RemoteControlClient/bin/NetworkScreenClient$ControlPanel$2.class and /dev/null differ
diff --git a/RemoteControlClient/bin/NetworkScreenClient$ControlPanel$3.class b/RemoteControlClient/bin/NetworkScreenClient$ControlPanel$3.class
deleted file mode 100644
index f23fd54..0000000
Binary files a/RemoteControlClient/bin/NetworkScreenClient$ControlPanel$3.class and /dev/null differ
diff --git a/RemoteControlClient/bin/NetworkScreenClient$ControlPanel$4.class b/RemoteControlClient/bin/NetworkScreenClient$ControlPanel$4.class
deleted file mode 100644
index 349a4c9..0000000
Binary files a/RemoteControlClient/bin/NetworkScreenClient$ControlPanel$4.class and /dev/null differ
diff --git a/RemoteControlClient/bin/NetworkScreenClient$ControlPanel.class b/RemoteControlClient/bin/NetworkScreenClient$ControlPanel.class
deleted file mode 100644
index 892b47f..0000000
Binary files a/RemoteControlClient/bin/NetworkScreenClient$ControlPanel.class and /dev/null differ
diff --git a/RemoteControlClient/bin/NetworkScreenClient.class b/RemoteControlClient/bin/NetworkScreenClient.class
deleted file mode 100644
index 2d5dcc9..0000000
Binary files a/RemoteControlClient/bin/NetworkScreenClient.class and /dev/null differ
diff --git a/RemoteControlClient/bin/ScreenPanel$1.class b/RemoteControlClient/bin/ScreenPanel$1.class
deleted file mode 100644
index aed5ac2..0000000
Binary files a/RemoteControlClient/bin/ScreenPanel$1.class and /dev/null differ
diff --git a/RemoteControlClient/bin/ScreenPanel$2.class b/RemoteControlClient/bin/ScreenPanel$2.class
deleted file mode 100644
index 47f6793..0000000
Binary files a/RemoteControlClient/bin/ScreenPanel$2.class and /dev/null differ
diff --git a/RemoteControlClient/bin/ScreenPanel$3.class b/RemoteControlClient/bin/ScreenPanel$3.class
deleted file mode 100644
index fec4ace..0000000
Binary files a/RemoteControlClient/bin/ScreenPanel$3.class and /dev/null differ
diff --git a/RemoteControlClient/bin/ScreenPanel$FPSCheckThread.class b/RemoteControlClient/bin/ScreenPanel$FPSCheckThread.class
deleted file mode 100644
index 0598a7f..0000000
Binary files a/RemoteControlClient/bin/ScreenPanel$FPSCheckThread.class and /dev/null differ
diff --git a/RemoteControlClient/bin/ScreenPanel$KeyboardThread$1.class b/RemoteControlClient/bin/ScreenPanel$KeyboardThread$1.class
deleted file mode 100644
index ebbf951..0000000
Binary files a/RemoteControlClient/bin/ScreenPanel$KeyboardThread$1.class and /dev/null differ
diff --git a/RemoteControlClient/bin/ScreenPanel$KeyboardThread.class b/RemoteControlClient/bin/ScreenPanel$KeyboardThread.class
deleted file mode 100644
index c8e718f..0000000
Binary files a/RemoteControlClient/bin/ScreenPanel$KeyboardThread.class and /dev/null differ
diff --git a/RemoteControlClient/bin/ScreenPanel$User32jna.class b/RemoteControlClient/bin/ScreenPanel$User32jna.class
deleted file mode 100644
index 77053f4..0000000
Binary files a/RemoteControlClient/bin/ScreenPanel$User32jna.class and /dev/null differ
diff --git a/RemoteControlClient/bin/ScreenPanel$showThread.class b/RemoteControlClient/bin/ScreenPanel$showThread.class
deleted file mode 100644
index 269aea0..0000000
Binary files a/RemoteControlClient/bin/ScreenPanel$showThread.class and /dev/null differ
diff --git a/RemoteControlClient/bin/ScreenPanel.class b/RemoteControlClient/bin/ScreenPanel.class
deleted file mode 100644
index 4695086..0000000
Binary files a/RemoteControlClient/bin/ScreenPanel.class and /dev/null differ
diff --git a/RemoteControlClient/pom.xml b/RemoteControlClient/pom.xml
deleted file mode 100644
index 5b1b63c..0000000
--- a/RemoteControlClient/pom.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-
- 4.0.0
- RemoteControlClient
- RemoteControlClient
- 0.0.1-SNAPSHOT
-
- src
-
-
- res
-
- **/*.java
-
-
-
-
-
- maven-compiler-plugin
- 3.7.0
-
-
- 1.8
-
-
-
-
-
-
-
- net.java.dev.jna
- jna
- 4.4.0
-
-
-
- net.java.dev.jna
- jna-platform
- 4.4.0
-
-
-
- org.xerial.snappy
- snappy-java
- 1.1.4-M3
-
-
-
-
\ No newline at end of file
diff --git a/RemoteControlClient/res/exit.png b/RemoteControlClient/res/exit.png
deleted file mode 100644
index 379c423..0000000
Binary files a/RemoteControlClient/res/exit.png and /dev/null differ
diff --git a/RemoteControlClient/res/minimize.png b/RemoteControlClient/res/minimize.png
deleted file mode 100644
index 545edae..0000000
Binary files a/RemoteControlClient/res/minimize.png and /dev/null differ
diff --git a/RemoteControlServer/.classpath b/RemoteControlServer/.classpath
deleted file mode 100644
index 4a683fb..0000000
--- a/RemoteControlServer/.classpath
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/RemoteControlServer/.gitignore b/RemoteControlServer/.gitignore
deleted file mode 100644
index b83d222..0000000
--- a/RemoteControlServer/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/target/
diff --git a/RemoteControlServer/.project b/RemoteControlServer/.project
deleted file mode 100644
index 8a31b2a..0000000
--- a/RemoteControlServer/.project
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
- RemoteControlServer
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- org.eclipse.m2e.core.maven2Builder
-
-
-
-
-
- org.eclipse.m2e.core.maven2Nature
- org.eclipse.jdt.core.javanature
-
-
diff --git a/RemoteControlServer/.settings/org.eclipse.jdt.core.prefs b/RemoteControlServer/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index e24b722..0000000
--- a/RemoteControlServer/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,13 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.8
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.release=disabled
-org.eclipse.jdt.core.compiler.source=1.8
diff --git a/RemoteControlServer/.settings/org.eclipse.m2e.core.prefs b/RemoteControlServer/.settings/org.eclipse.m2e.core.prefs
deleted file mode 100644
index f897a7f..0000000
--- a/RemoteControlServer/.settings/org.eclipse.m2e.core.prefs
+++ /dev/null
@@ -1,4 +0,0 @@
-activeProfiles=
-eclipse.preferences.version=1
-resolveWorkspaceProjects=true
-version=1
diff --git a/RemoteControlServer/bin/DebugMessage.class b/RemoteControlServer/bin/DebugMessage.class
deleted file mode 100644
index 463ba44..0000000
Binary files a/RemoteControlServer/bin/DebugMessage.class and /dev/null differ
diff --git a/RemoteControlServer/bin/GDI32.class b/RemoteControlServer/bin/GDI32.class
deleted file mode 100644
index 751b7d1..0000000
Binary files a/RemoteControlServer/bin/GDI32.class and /dev/null differ
diff --git a/RemoteControlServer/bin/JNAScreenShot.class b/RemoteControlServer/bin/JNAScreenShot.class
deleted file mode 100644
index d768712..0000000
Binary files a/RemoteControlServer/bin/JNAScreenShot.class and /dev/null differ
diff --git a/RemoteControlServer/bin/NetworkScreenServer$1.class b/RemoteControlServer/bin/NetworkScreenServer$1.class
deleted file mode 100644
index d62c337..0000000
Binary files a/RemoteControlServer/bin/NetworkScreenServer$1.class and /dev/null differ
diff --git a/RemoteControlServer/bin/NetworkScreenServer$CursorThread.class b/RemoteControlServer/bin/NetworkScreenServer$CursorThread.class
deleted file mode 100644
index 3ab9d01..0000000
Binary files a/RemoteControlServer/bin/NetworkScreenServer$CursorThread.class and /dev/null differ
diff --git a/RemoteControlServer/bin/NetworkScreenServer$ImgDoubleBufferTh.class b/RemoteControlServer/bin/NetworkScreenServer$ImgDoubleBufferTh.class
deleted file mode 100644
index 61c20df..0000000
Binary files a/RemoteControlServer/bin/NetworkScreenServer$ImgDoubleBufferTh.class and /dev/null differ
diff --git a/RemoteControlServer/bin/NetworkScreenServer$KeyBoardThread.class b/RemoteControlServer/bin/NetworkScreenServer$KeyBoardThread.class
deleted file mode 100644
index c889dd9..0000000
Binary files a/RemoteControlServer/bin/NetworkScreenServer$KeyBoardThread.class and /dev/null differ
diff --git a/RemoteControlServer/bin/NetworkScreenServer$MainPanel$1.class b/RemoteControlServer/bin/NetworkScreenServer$MainPanel$1.class
deleted file mode 100644
index 8eb3290..0000000
Binary files a/RemoteControlServer/bin/NetworkScreenServer$MainPanel$1.class and /dev/null differ
diff --git a/RemoteControlServer/bin/NetworkScreenServer$MainPanel$2.class b/RemoteControlServer/bin/NetworkScreenServer$MainPanel$2.class
deleted file mode 100644
index 2c5a2a9..0000000
Binary files a/RemoteControlServer/bin/NetworkScreenServer$MainPanel$2.class and /dev/null differ
diff --git a/RemoteControlServer/bin/NetworkScreenServer$MainPanel.class b/RemoteControlServer/bin/NetworkScreenServer$MainPanel.class
deleted file mode 100644
index 02fdbbd..0000000
Binary files a/RemoteControlServer/bin/NetworkScreenServer$MainPanel.class and /dev/null differ
diff --git a/RemoteControlServer/bin/NetworkScreenServer$ServerSocketCloseThread.class b/RemoteControlServer/bin/NetworkScreenServer$ServerSocketCloseThread.class
deleted file mode 100644
index 0b70043..0000000
Binary files a/RemoteControlServer/bin/NetworkScreenServer$ServerSocketCloseThread.class and /dev/null differ
diff --git a/RemoteControlServer/bin/NetworkScreenServer$User32jna.class b/RemoteControlServer/bin/NetworkScreenServer$User32jna.class
deleted file mode 100644
index 4a16ecd..0000000
Binary files a/RemoteControlServer/bin/NetworkScreenServer$User32jna.class and /dev/null differ
diff --git a/RemoteControlServer/bin/NetworkScreenServer.class b/RemoteControlServer/bin/NetworkScreenServer.class
deleted file mode 100644
index 083cad7..0000000
Binary files a/RemoteControlServer/bin/NetworkScreenServer.class and /dev/null differ
diff --git a/RemoteControlServer/bin/User32.class b/RemoteControlServer/bin/User32.class
deleted file mode 100644
index 90b4377..0000000
Binary files a/RemoteControlServer/bin/User32.class and /dev/null differ
diff --git a/RemoteControlServer/bin/cursor.gif b/RemoteControlServer/bin/cursor.gif
deleted file mode 100644
index 29007f6..0000000
Binary files a/RemoteControlServer/bin/cursor.gif and /dev/null differ
diff --git a/RemoteControlServer/pom.xml b/RemoteControlServer/pom.xml
deleted file mode 100644
index 5c88dd5..0000000
--- a/RemoteControlServer/pom.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-
- 4.0.0
- RemoteControlServer
- RemoteControlServer
- 0.0.1-SNAPSHOT
-
- src
-
-
- res
-
- **/*.java
-
-
-
-
-
- maven-compiler-plugin
- 3.7.0
-
-
- 1.8
-
-
-
-
-
-
-
- net.java.dev.jna
- jna
- 4.4.0
-
-
-
- net.java.dev.jna
- jna-platform
- 4.4.0
-
-
-
- org.xerial.snappy
- snappy-java
- 1.1.4-M3
-
-
-
-
\ No newline at end of file
diff --git a/RemoteControlServer/res/cursor.gif b/RemoteControlServer/res/cursor.gif
deleted file mode 100644
index 29007f6..0000000
Binary files a/RemoteControlServer/res/cursor.gif and /dev/null differ
diff --git a/ScreenCaptureSample/ScreenCaptureSample.iml b/ScreenCaptureSample/ScreenCaptureSample.iml
new file mode 100644
index 0000000..787555e
--- /dev/null
+++ b/ScreenCaptureSample/ScreenCaptureSample.iml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ScreenCaptureSample/pom.xml b/ScreenCaptureSample/pom.xml
new file mode 100644
index 0000000..30df3c3
--- /dev/null
+++ b/ScreenCaptureSample/pom.xml
@@ -0,0 +1,44 @@
+
+
+ 4.0.0
+
+ groupId
+ ScreenCaptureSample
+ 1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 1.8
+
+
+
+
+
+
+
+ net.java.dev.jna
+ jna
+ 4.1.0
+
+
+
+ net.java.dev.jna
+ jna-platform
+ 4.1.0
+
+
+
+ org.xerial.snappy
+ snappy-java
+ 1.1.4
+
+
+
+
+
\ No newline at end of file
diff --git a/ScreenCaptureSample/src/main/java/dydtjr1128/JNAScreenShot.java b/ScreenCaptureSample/src/main/java/dydtjr1128/JNAScreenShot.java
new file mode 100644
index 0000000..da581d0
--- /dev/null
+++ b/ScreenCaptureSample/src/main/java/dydtjr1128/JNAScreenShot.java
@@ -0,0 +1,177 @@
+package dydtjr1128;
+
+import com.sun.jna.Native;
+import com.sun.jna.platform.win32.WinDef.HBITMAP;
+import com.sun.jna.platform.win32.WinDef.HDC;
+import com.sun.jna.platform.win32.WinDef.HWND;
+import com.sun.jna.platform.win32.WinGDI.BITMAPINFO;
+import com.sun.jna.platform.win32.WinGDI.BITMAPINFOHEADER;
+import com.sun.jna.platform.win32.WinNT.HANDLE;
+import com.sun.jna.win32.W32APIOptions;
+
+import java.awt.*;
+import java.awt.image.*;
+
+public class JNAScreenShot {
+
+ public static BufferedImage getScreenshot(Rectangle bounds) {
+
+ HDC windowDC = GDI.GetDC(USER.GetDesktopWindow());
+ HBITMAP outputBitmap = GDI.CreateCompatibleBitmap(windowDC, bounds.width, bounds.height);
+ try {
+ HDC blitDC = GDI.CreateCompatibleDC(windowDC);
+ try {
+ HANDLE oldBitmap = GDI.SelectObject(blitDC, outputBitmap);
+ try {
+ GDI.BitBlt(blitDC, 0, 0, bounds.width, bounds.height, windowDC, bounds.x, bounds.y, GDI32.SRCCOPY);
+ //SRCCOPY�� ������ �״�� �����ؿ��� �� ����
+ } finally {
+ GDI.SelectObject(blitDC, oldBitmap);
+ }
+ BITMAPINFO bi = new BITMAPINFO(40);
+ bi.bmiHeader.biSize = 40;
+
+
+ boolean ok = GDI.GetDIBits(blitDC, outputBitmap, 0, bounds.height, (byte[]) null, bi, 0x00);
+
+
+ if (ok) {
+ System.out.println("11111");
+ BITMAPINFOHEADER bih = bi.bmiHeader;
+ System.out.println("22222");
+ bih.biHeight = -Math.abs(bih.biHeight);
+ System.out.println("33333");
+ bi.bmiHeader.biCompression = 0;
+ return bufferedImageFromBitmap(blitDC, outputBitmap, bi);
+ } else {
+ return null;
+ }
+ } finally {
+ GDI.DeleteObject(blitDC);
+ }
+ } finally {
+ GDI.DeleteObject(outputBitmap);
+ }
+ }
+ HBITMAP ScreenCapture(HWND hWnd)
+ {
+ int ScreenWidth = 1920;
+ int ScreenHeight = 1080;
+ HDC hScrDC, hMemDC;
+ HBITMAP hBitmap;
+
+ HDC windowDC = GDI.GetDC(USER.GetDesktopWindow());
+ hMemDC = GDI.CreateCompatibleDC(windowDC);
+ hBitmap = GDI.CreateCompatibleBitmap(windowDC, ScreenWidth, ScreenHeight);
+ GDI.SelectObject(hMemDC, hBitmap);
+
+ GDI.BitBlt(hMemDC, 0, 0, ScreenWidth, ScreenHeight, windowDC, 0, 0, GDI.SRCCOPY);
+
+ GDI.DeleteDC(hMemDC);
+ GDI.DeleteDC(windowDC);
+ return hBitmap;
+ }
+
+ private static BufferedImage bufferedImageFromBitmap(HDC blitDC, HBITMAP outputBitmap, BITMAPINFO bi) {
+ BITMAPINFOHEADER bih = bi.bmiHeader;
+ int height = Math.abs(bih.biHeight);
+ final ColorModel cm;
+ final DataBuffer buffer;
+ final WritableRaster raster;
+ int strideBits = (bih.biWidth * bih.biBitCount);
+ int strideBytesAligned = (((strideBits - 1) | 0x1F) + 1) >> 3;//8������
+ final int strideElementsAligned;
+ System.out.println(strideBits + " " + strideBytesAligned + " " + bih.biBitCount);
+ bi.bmiHeader.biPlanes=1;
+ bi.bmiHeader.biBitCount=24;
+ bi.bmiHeader.biSizeImage = ( ( bi.bmiHeader.biWidth * bi.bmiHeader.biBitCount + 31 ) & ~31 ) / 8 * bi.bmiHeader.biHeight;
+ bi.bmiHeader.biCompression = 0;
+ switch (bih.biBitCount) {
+ case 16:
+ strideElementsAligned = strideBytesAligned / 2;
+ cm = new DirectColorModel(16, 0x7C00, 0x3E0, 0x1F);
+ buffer = new DataBufferUShort(strideElementsAligned * height);
+ raster = Raster.createPackedRaster(buffer, bih.biWidth, height, strideElementsAligned,
+ ((DirectColorModel) cm).getMasks(), null);
+ break;
+ case 24:
+ strideElementsAligned = strideBytesAligned/3 ;
+ //image.setData(Raster.createRaster(screenImage.getSampleModel(),
+ //new DataBufferByte(imageByte, imageByte.length), new Point()));
+ System.out.println("-------------------------");
+ cm = new DirectColorModel(24, 0xFF0000, 0xFF00, 0xFF);
+ buffer = new DataBufferByte(strideElementsAligned * height);//DataBufferInt(strideElementsAligned * height);
+ System.out.println(bih.biWidth + " " + bih.biHeight + " " + strideElementsAligned);
+ raster = Raster.createPackedRaster(buffer, bih.biWidth, height, strideElementsAligned,
+ ((DirectColorModel) cm).getMasks(), null);
+ System.out.println("rrrrrrrrrrrrrrrrrrrrrrrrrrr");
+ break;
+ case 32:
+ strideElementsAligned = strideBytesAligned/4 ;
+ //image.setData(Raster.createRaster(screenImage.getSampleModel(),
+ //new DataBufferByte(imageByte, imageByte.length), new Point()));
+ cm = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF);
+ buffer = new DataBufferInt(strideElementsAligned * height);
+ System.out.println(bih.biWidth + " " + bih.biHeight + " " + strideElementsAligned);
+ raster = Raster.createPackedRaster(buffer, bih.biWidth, height, strideElementsAligned,
+ ((DirectColorModel) cm).getMasks(), null);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported bit count: " + bih.biBitCount);
+ }
+ boolean ok;
+ System.out.println(buffer.getDataType());
+ switch (buffer.getDataType()) {
+ case DataBuffer.TYPE_BYTE: {
+ byte[] pixels = ((DataBufferByte) buffer).getData();
+ ok = GDI.GetDIBits(blitDC, outputBitmap, 0, raster.getHeight(), pixels, bi, 0);
+ break;
+ }
+ case DataBuffer.TYPE_INT: {
+ int[] pixels = ((DataBufferInt) buffer).getData();
+ ok = GDI.GetDIBits(blitDC, outputBitmap, 0, raster.getHeight(), pixels, bi, 0);
+ }
+ break;
+ case DataBuffer.TYPE_USHORT: {
+ short[] pixels = ((DataBufferUShort) buffer).getData();
+ ok = GDI.GetDIBits(blitDC, outputBitmap, 0, raster.getHeight(), pixels, bi, 0);
+ }
+ break;
+ default:
+ throw new AssertionError("Unexpected buffer element type: " + buffer.getDataType());
+ }
+ if (ok) {
+ return new BufferedImage(cm, raster, false, null);
+ } else {
+ return null;
+ }
+ }
+
+ private static final User32 USER = User32.INSTANCE;
+
+ private static final GDI32 GDI = GDI32.INSTANCE;
+
+}
+
+interface GDI32 extends com.sun.jna.platform.win32.GDI32 {
+ GDI32 INSTANCE = (GDI32) Native.loadLibrary(GDI32.class);
+
+ boolean BitBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HDC hdcSrc, int nXSrc, int nYSrc,
+ int dwRop);
+
+ HDC GetDC(HWND hWnd);
+
+ boolean GetDIBits(HDC dc, HBITMAP bmp, int startScan, int scanLines, byte[] pixels, BITMAPINFO bi, int usage);
+
+ boolean GetDIBits(HDC dc, HBITMAP bmp, int startScan, int scanLines, short[] pixels, BITMAPINFO bi, int usage);
+
+ boolean GetDIBits(HDC dc, HBITMAP bmp, int startScan, int scanLines, int[] pixels, BITMAPINFO bi, int usage);
+
+ int SRCCOPY = 0xCC0020;
+}
+
+interface User32 extends com.sun.jna.platform.win32.User32 {
+ User32 INSTANCE = (User32) Native.loadLibrary(User32.class, W32APIOptions.UNICODE_OPTIONS);
+
+ HWND GetDesktopWindow();
+}
\ No newline at end of file
diff --git a/ScreenCaptureSample/src/main/java/dydtjr1128/JNAScreenShot2.java b/ScreenCaptureSample/src/main/java/dydtjr1128/JNAScreenShot2.java
new file mode 100644
index 0000000..de4a4df
--- /dev/null
+++ b/ScreenCaptureSample/src/main/java/dydtjr1128/JNAScreenShot2.java
@@ -0,0 +1,120 @@
+package dydtjr1128;
+
+import com.sun.jna.platform.win32.WinDef.HBITMAP;
+import com.sun.jna.platform.win32.WinDef.HDC;
+import com.sun.jna.platform.win32.WinGDI.BITMAPINFO;
+import com.sun.jna.platform.win32.WinGDI.BITMAPINFOHEADER;
+import com.sun.jna.platform.win32.WinNT.HANDLE;
+
+import java.awt.*;
+import java.awt.image.*;
+
+public class JNAScreenShot2 {
+
+ public static BufferedImage getScreenshot(Rectangle bounds) {
+
+ HDC windowDC = GDI.GetDC(USER.GetDesktopWindow());
+ HBITMAP outputBitmap =
+ GDI.CreateCompatibleBitmap(windowDC,
+ bounds.width, bounds.height);
+ try {
+ HDC blitDC = GDI.CreateCompatibleDC(windowDC);
+ try {
+ HANDLE oldBitmap =
+ GDI.SelectObject(blitDC, outputBitmap);
+ try {
+ GDI.BitBlt(blitDC,
+ 0, 0, bounds.width, bounds.height,
+ windowDC,
+ bounds.x, bounds.y,
+ GDI32.SRCCOPY);
+ } finally {
+ GDI.SelectObject(blitDC, oldBitmap);
+ }
+ BITMAPINFO bi = new BITMAPINFO(40);
+ bi.bmiHeader.biSize = 40;
+ boolean ok =
+ GDI.GetDIBits(blitDC, outputBitmap, 0, bounds.height,
+ (byte[]) null, bi, 0);
+ if (ok) {
+ BITMAPINFOHEADER bih = bi.bmiHeader;
+ bih.biHeight = -Math.abs(bih.biHeight);
+ bi.bmiHeader.biCompression = 0;
+ return bufferedImageFromBitmap(blitDC, outputBitmap, bi);
+ } else {
+ return null;
+ }
+ } finally {
+ GDI.DeleteObject(blitDC);
+ }
+ } finally {
+ GDI.DeleteObject(outputBitmap);
+ }
+ }
+
+ private static BufferedImage bufferedImageFromBitmap(HDC blitDC, HBITMAP outputBitmap, BITMAPINFO bi) {
+ BITMAPINFOHEADER bih = bi.bmiHeader;
+ int height = Math.abs(bih.biHeight);
+ final ColorModel cm;
+ final DataBuffer buffer;
+ final WritableRaster raster;
+ int strideBits =
+ (bih.biWidth * bih.biBitCount);
+ int strideBytesAligned =
+ (((strideBits - 1) | 0x1F) + 1) >> 3;
+ final int strideElementsAligned;
+ switch (bih.biBitCount) {
+ case 16:
+ strideElementsAligned = strideBytesAligned / 2;
+ cm = new DirectColorModel(16, 0x7C00, 0x3E0, 0x1F);
+ buffer =
+ new DataBufferUShort(strideElementsAligned * height);
+ raster =
+ Raster.createPackedRaster(buffer,
+ bih.biWidth, height,
+ strideElementsAligned,
+ ((DirectColorModel) cm).getMasks(),
+ null);
+ break;
+ case 32:
+ strideElementsAligned = strideBytesAligned / 4;
+ cm = new DirectColorModel(32, 0xFF0000, 0xFF00, 0xFF);
+ buffer =
+ new DataBufferInt(strideElementsAligned * height);
+ raster =
+ Raster.createPackedRaster(buffer,
+ bih.biWidth, height,
+ strideElementsAligned,
+ ((DirectColorModel) cm).getMasks(),
+ null);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported bit count: " + bih.biBitCount);
+ }
+ final boolean ok;
+ switch (buffer.getDataType()) {
+ case DataBuffer.TYPE_INT: {
+ int[] pixels = ((DataBufferInt) buffer).getData();
+ ok = GDI.GetDIBits(blitDC, outputBitmap, 0, raster.getHeight(), pixels, bi, 0);
+ }
+ break;
+ case DataBuffer.TYPE_USHORT: {
+ short[] pixels = ((DataBufferUShort) buffer).getData();
+ ok = GDI.GetDIBits(blitDC, outputBitmap, 0, raster.getHeight(), pixels, bi, 0);
+ }
+ break;
+ default:
+ throw new AssertionError("Unexpected buffer element type: " + buffer.getDataType());
+ }
+ if (ok) {
+ return new BufferedImage(cm, raster, false, null);
+ } else {
+ return null;
+ }
+ }
+
+ private static final User32 USER = User32.INSTANCE;
+
+ private static final GDI32 GDI = GDI32.INSTANCE;
+
+}
diff --git a/ScreenCaptureSample/src/main/java/dydtjr1128/ScreenCapture.java b/ScreenCaptureSample/src/main/java/dydtjr1128/ScreenCapture.java
new file mode 100644
index 0000000..c8ccf8b
--- /dev/null
+++ b/ScreenCaptureSample/src/main/java/dydtjr1128/ScreenCapture.java
@@ -0,0 +1,270 @@
+package dydtjr1128;
+
+import com.sun.image.codec.jpeg.JPEGCodec;
+import com.sun.image.codec.jpeg.JPEGImageDecoder;
+import com.sun.image.codec.jpeg.JPEGImageEncoder;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.SynchronousQueue;
+
+
+public class ScreenCapture extends JFrame {
+ private JLabel FPSlabel;
+ private int FPScount = 0;
+ private int screenWidth, screenHeight;
+ int buffersize = 1;
+ byte imgbyte[][] = new byte[buffersize][];
+ SynchronousQueue imageBlockingQueue2 = new SynchronousQueue<>();
+ BlockingQueue imageBlockingQueue = new ArrayBlockingQueue<>(3);
+
+ public ScreenCapture() {
+ setTitle("screen");
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ setLayout(null);
+ //this.setAlwaysOnTop(true);
+ ScreenPanel sp = new ScreenPanel();
+ setContentPane(sp);
+ setSize(800, 800);
+ setVisible(true);
+
+ Thread th = new Thread(sp);
+ th.start();
+ FPSCheckThread fps = new FPSCheckThread();
+ fps.start();
+ }
+
+ class ScreenPanel extends JPanel implements Runnable {
+ BufferedImage image;
+ int screenWidth, screenHeight;
+ Robot robot = null;
+
+ public ScreenPanel() {
+ screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
+ screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
+ FPSlabel = new JLabel("FPS : " + Integer.toString(FPScount));
+ FPSlabel.setFont(new Font("�������", Font.BOLD, 20));
+ FPSlabel.setBounds(10, 10, 100, 50);
+ add(FPSlabel);
+ addMouseListener(new MouseListener() {
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() == 1 && e.getButton() == e.BUTTON3) {
+ //System.out.println("4444");
+ robot.mouseMove(e.getX() * screenWidth / getWidth(), e.getY() * screenHeight / getHeight());
+ robot.mousePress(MouseEvent.BUTTON3_MASK);
+ robot.mouseRelease(MouseEvent.BUTTON3_MASK);
+ } else if (e.getClickCount() == 2) {
+ //mx : wx = getwidth : winwidth
+ robot.mouseMove(e.getX() * screenWidth / getWidth(), e.getY() * screenHeight / getHeight());
+ robot.mousePress(MouseEvent.BUTTON1_MASK);
+ robot.mouseRelease(MouseEvent.BUTTON1_MASK);
+ robot.mousePress(MouseEvent.BUTTON1_MASK);
+ robot.mouseRelease(MouseEvent.BUTTON1_MASK);
+ }
+ }
+
+ public void mousePressed(MouseEvent e) {
+
+ }
+
+ public void mouseReleased(MouseEvent e) {
+
+ }
+
+ public void mouseEntered(MouseEvent e) {
+
+ }
+
+ public void mouseExited(MouseEvent e) {
+
+ }
+ });
+ try {
+ robot = new Robot();
+ } catch (AWTException e) {
+ e.printStackTrace();
+ }
+ screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
+ screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
+ image = robot.createScreenCapture(new Rectangle(0, 0, screenWidth, screenHeight));
+
+ repaint();
+ }
+
+ @Override
+ protected void paintComponent(Graphics g) {
+
+ super.paintComponent(g);
+ try {
+ FPScount++;
+ BufferedImage ii = toBufferedImage(imageBlockingQueue2.take());
+ g.drawImage(ii, 0, 0, getWidth(), getHeight(), this);
+ //byte[] imageBytes = ((DataBufferByte) ii.getData().getDataBuffer()).getData();
+ //System.out.println(imageBytes.length);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+
+ }
+
+ /*private BufferedImage screenShot(){
+ //Creating an rbg array of total pixels
+ int[] pixels = new int[screenWidth * screenHeight];
+ int bindex;
+ // allocate space for RBG pixels
+ ByteBuffer fb = ByteBuffer.allocateDirect(screenWidth * screenHeight * 3);
+
+ // grab a copy of the current frame contents as RGB
+ GL11.glReadPixels(0, 0, screenWidth, screenHeight, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, fb);
+
+ BufferedImage imageIn = new BufferedImage(screenWidth, screenHeight,BufferedImage.TYPE_INT_RGB);
+ // convert RGB data in ByteBuffer to integer array
+ for (int i=0; i < pixels.length; i++) {
+ bindex = i * 3;
+ pixels[i] =
+ ((fb.get(bindex) << 16)) +
+ ((fb.get(bindex+1) << 8)) +
+ ((fb.get(bindex+2) << 0));
+ }
+ //Allocate colored pixel to buffered Image
+ imageIn.setRGB(0, 0, screenWidth, screenHeight, pixels, 0 , screenWidth);
+
+ //Creating the transformation direction (horizontal)
+ AffineTransform at = AffineTransform.getScaleInstance(1, -1);
+ at.translate(0, -imageIn.getHeight(null));
+
+ //Applying transformation
+ AffineTransformOp opRotated = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
+ BufferedImage imageOut = opRotated.filter(imageIn, null);
+ return imageOut;
+ }*/
+ public void run() {
+ Rectangle rect = new Rectangle(0, 0, screenWidth, screenHeight);
+ double avg = 0;
+ int count = 0;
+ while (true) {
+ try {
+
+ long s = System.currentTimeMillis();
+ //image = JNAScreenShot2.getScreenshot(rect);
+ image = robot.createScreenCapture(rect);
+ //image = getScaledImage(image, 1920, 1080);
+
+ //9~11frame
+ imageBlockingQueue2.add(toByteArray(image));
+ avg += 1/((System.currentTimeMillis() - s) / (double) 1000);
+ System.out.println(imageBlockingQueue2.size() + " " + avg / count++);
+ repaint();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public byte[] toByteArray(BufferedImage image) throws IOException {//ImageIO보다 빠름
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(baos);
+ encoder.encode(image);
+ return baos.toByteArray();
+ }
+
+ public BufferedImage toBufferedImage(byte[] image) throws IOException {//ImageIO보다 빠름
+ ByteArrayInputStream bais = new ByteArrayInputStream(image);
+ JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(bais);
+
+ return decoder.decodeAsBufferedImage();
+ }
+
+ public BufferedImage getScaledImage(BufferedImage myImage, int screenWidth, int screenHeight) {
+ BufferedImage background = new BufferedImage(screenWidth, screenHeight, BufferedImage.TYPE_INT_RGB);
+ Graphics2D g = background.createGraphics();
+ //g.setColor(Color.WHITE);
+ g.drawImage(myImage, 0, 0, screenWidth, screenHeight, null);
+ g.dispose();
+ return background;
+ }
+
+ /*class ImgDoubleBufferTh extends Thread {
+ BufferedImage bufferimage;
+
+ public void run() {
+ int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
+ int screennHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
+ BufferedImage screenImage;
+ Robot robot = null;
+ try {
+ robot = new Robot();
+ } catch (AWTException e) {
+ }
+
+ Rectangle rect = new Rectangle(0, 0, screenWidth, screennHeight);
+ int ff = 1;
+ long starttime, endtime;
+ while (true) {
+ starttime = System.nanoTime();
+ bufferimage = robot.createScreenCapture(rect);//JNAScreenShot.getScreenshot(rect);//robot.createScreenCapture(rect);
+ endtime = System.nanoTime() - starttime;
+ System.out.println("capture " + endtime);
+ bufferimage = getScaledImage(bufferimage, 1920, 1080);
+ byte[] imageByte = ((DataBufferByte) bufferimage.getRaster().getDataBuffer()).getData();
+
+ try {
+ byte[] bbb = Snappy.compress(imageByte);
+ b.addElement(bbb);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ *//* starttime = System.nanoTime();
+ bb.addElement(bufferimage);
+ endtime = System.nanoTime() -starttime;
+ System.out.println("add " + endtime); *//*
+
+
+ }
+
+ }
+ }*/
+
+ class FPSCheckThread extends Thread {
+ int sum = 0;
+ double avg = 0;
+ int roop = 0;
+
+ public void run() {
+ while (true) {
+ try {
+
+ sleep(1000);
+ sum += FPScount;
+ roop++;
+ avg = (double) sum / roop;
+ avg = Double.parseDouble(String.format("%.3f", avg));
+
+ FPSlabel.setText("FPS : " + Integer.toString(FPScount) + " " + Double.toString(avg));
+ //repaint();
+ System.out.println("FPS : " + FPScount + " " + avg);
+
+ FPScount = 0;
+
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ }
+
+ public static void main(String[] args) {
+ new ScreenCapture();
+ }
+}