kristian / system-hook

Global Keyboard / Mouse Hook for Java applications.
MIT License
270 stars 48 forks source link

Input key issue with Omsi 2 #6

Closed Safraann closed 8 years ago

Safraann commented 8 years ago

Hello, I try to get input keys coming from the game Omsi 2, especially one in particular: the touch 6. Everything works very well if I am on google chrome, my desktop or even in a folder, but as soon as Windows is on Omsi 2 (fullscreen mode or not), the console (in eclipse ide) indicates me nothing more :/ Thank you in advance =)

PS = My code if necessary : `package fr.plaigon.djkh;

import java.awt.Color; import java.awt.Robot; import java.awt.event.KeyEvent;

import javax.swing.JFrame;

import lc.kra.system.keyboard.GlobalKeyboardHook; import lc.kra.system.keyboard.event.GlobalKeyAdapter; import lc.kra.system.keyboard.event.GlobalKeyEvent;

public class Main extends JFrame { private static final long serialVersionUID = 1L; private static boolean run = true; private static short pressingTime = 0;

public Main()
{
    this.setBounds(500, 250, 300, 150);
    this.setTitle("Omsi Plaigon Input");
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.getContentPane().setBackground(new Color(64, 64, 64));
    this.setLocationRelativeTo(null);
    this.setResizable(false);this.setLayout(null);
    this.setVisible(true);
}

public static void main(String[] args)
{
    new Main();
    // might throw a UnsatisfiedLinkError if the native library fails to load or a RuntimeException if hooking fails 
    GlobalKeyboardHook keyboardHook = new GlobalKeyboardHook();

    System.out.println("Global keyboard hook successfully started, press [escape] key to shutdown.");
    keyboardHook.addKeyListener(new GlobalKeyAdapter()
    {
        @Override
        public void keyPressed(GlobalKeyEvent event)
        {
            System.out.println(event);
            if(event.getVirtualKeyCode() == GlobalKeyEvent.VK_6)
                pressingTime++;
        }
        @Override
        public void keyReleased(GlobalKeyEvent event)
        {
            System.out.println(event);
            if(pressingTime >= 50 && event.getVirtualKeyCode() == GlobalKeyEvent.VK_6)
            {
                try
                {
                    Thread.sleep(500);  
                    Robot robot = new Robot();
                    robot.setAutoWaitForIdle(false);
                    robot.keyPress(KeyEvent.VK_6);
                    System.out.println("oui oui oui ");
                    pressingTime = 0;
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
        }
    });

    try
    {
        while(run)
        {
            Thread.sleep(128);
        }
    }
    catch(InterruptedException e)
    {
    }
    finally
    {
          keyboardHook.shutdownHook();
    }
}

} `

Safraann commented 8 years ago

Issue closed ! Duplication post fail, sorry for disagreement