Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.jnativehook.GlobalScreen;
- import org.jnativehook.NativeHookException;
- import org.jnativehook.keyboard.NativeKeyEvent;
- import org.jnativehook.keyboard.NativeKeyListener;
- import org.jnativehook.mouse.NativeMouseEvent;
- import org.jnativehook.mouse.NativeMouseInputListener;
- import org.jnativehook.mouse.NativeMouseWheelEvent;
- import org.jnativehook.mouse.NativeMouseWheelListener;
- public class Listener implements NativeKeyListener, NativeMouseInputListener, NativeMouseWheelListener
- {
- private String macroPathFile;
- private String pauseKey;
- public void nativeKeyPressed(NativeKeyEvent e)
- {
- System.out.println("Key Pressed: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
- try {
- writeState("KP:" + NativeKeyEvent.getKeyText(e.getKeyCode()));
- } catch (IOException ex) {
- Logger.getLogger(Listener.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public void nativeKeyReleased(NativeKeyEvent e)
- {
- System.out.println("Key Released: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
- }
- public void nativeKeyTyped(NativeKeyEvent e)
- {
- System.out.println("Key Typed: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
- }
- public void nativeMouseWheelMoved(NativeMouseWheelEvent e)
- {
- System.out.println("Mouse Wheel Moved: " + e.getWheelRotation());
- }
- public void nativeMouseClicked(NativeMouseEvent e)
- {
- System.out.println("Mouse Clicked: " + e.getClickCount());
- }
- public void nativeMousePressed(NativeMouseEvent e)
- {
- System.out.println("Mouse Pressed: " + e.getButton());
- }
- public void nativeMouseReleased(NativeMouseEvent e)
- {
- System.out.println("Mouse Released: " + e.getButton());
- }
- public void nativeMouseMoved(NativeMouseEvent e)
- {
- System.out.println("Mouse Moved: " + e.getX() + ", " + e.getY());
- }
- public void nativeMouseDragged(NativeMouseEvent e)
- {
- System.out.println("Mouse Dragged: " + e.getX() + ", " + e.getY());
- }
- public void setMacroAttribut(String macroPathFile, String pauseKey)
- {
- this.macroPathFile = macroPathFile;
- this.pauseKey = pauseKey;
- }
- public void writeState(String text) throws IOException
- {
- FileWriter file = new FileWriter(macroPathFile, true);
- file.write("\n");
- file.append(text + "\n\r");
- file.close();
- }
- public void start() throws NativeHookException
- {
- GlobalScreen.registerNativeHook();
- // Construct the example object.
- Listener run = new Listener();
- // Add the appropriate listeners.
- GlobalScreen.addNativeMouseListener(run);
- GlobalScreen.addNativeMouseMotionListener(run);
- GlobalScreen.addNativeMouseWheelListener(run);
- GlobalScreen.addNativeKeyListener(run);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement