Advertisement
Guest User

Untitled

a guest
Aug 19th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. package fr.plaigon.djkh;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Robot;
  5. import java.awt.event.KeyEvent;
  6.  
  7. import javax.swing.JFrame;
  8.  
  9. import lc.kra.system.keyboard.GlobalKeyboardHook;
  10. import lc.kra.system.keyboard.event.GlobalKeyAdapter;
  11. import lc.kra.system.keyboard.event.GlobalKeyEvent;
  12.  
  13. public class Main extends JFrame
  14. {
  15. private static final long serialVersionUID = 1L;
  16. private static boolean run = true;
  17. private static short pressingTime = 0;
  18.  
  19. public Main()
  20. {
  21. this.setBounds(500, 250, 300, 150);
  22. this.setTitle("Omsi Plaigon Input");
  23. this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  24. this.getContentPane().setBackground(new Color(64, 64, 64));
  25. this.setLocationRelativeTo(null);
  26. this.setResizable(false);this.setLayout(null);
  27. this.setVisible(true);
  28. }
  29.  
  30. public static void main(String[] args)
  31. {
  32. new Main();
  33. // might throw a UnsatisfiedLinkError if the native library fails to load or a RuntimeException if hooking fails
  34. GlobalKeyboardHook keyboardHook = new GlobalKeyboardHook();
  35.  
  36. System.out.println("Global keyboard hook successfully started, press [escape] key to shutdown.");
  37. keyboardHook.addKeyListener(new GlobalKeyAdapter()
  38. {
  39. @Override
  40. public void keyPressed(GlobalKeyEvent event)
  41. {
  42. System.out.println(event);
  43. if(event.getVirtualKeyCode() == GlobalKeyEvent.VK_6)
  44. pressingTime++;
  45. }
  46. @Override
  47. public void keyReleased(GlobalKeyEvent event)
  48. {
  49. System.out.println(event);
  50. if(pressingTime >= 50 && event.getVirtualKeyCode() == GlobalKeyEvent.VK_6)
  51. {
  52. try
  53. {
  54. Thread.sleep(500);
  55. Robot robot = new Robot();
  56. robot.setAutoWaitForIdle(false);
  57. robot.keyPress(KeyEvent.VK_6);
  58. System.out.println("oui oui oui ");
  59. pressingTime = 0;
  60. }
  61. catch (Exception e)
  62. {
  63. e.printStackTrace();
  64. }
  65. }
  66. }
  67. });
  68.  
  69. try
  70. {
  71. while(run)
  72. {
  73. Thread.sleep(128);
  74. }
  75. }
  76. catch(InterruptedException e)
  77. {
  78. }
  79. finally
  80. {
  81. keyboardHook.shutdownHook();
  82. }
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement