Question

I am trying to make a mouse recorder, I cant seem to get a mouse listener to work with a console, is this possable and how would I go about it Thanks.

Was it helpful?

Solution

Unless you wrote your own console that fired mouse events, I dont' think you're going to be able to do it. What widget are you going to register your mouselistener against otherwise? The console isn't a swing component, therefore, no swing events.

OTHER TIPS

You can do this by using global hooks. In order to use them you'll need to include some natives or try the same using JNI (see: wikipedia).

Two examples:

Edit:

  • Example for some playback functionalities:

    import java.awt.AWTException;
    import java.awt.DisplayMode;
    import java.awt.MouseInfo;
    import java.awt.PointerInfo;
    import java.awt.Robot;
    import java.util.Random;
    
    // class instructions
    
    try {
        PointerInfo pntInfo = MouseInfo.getPointerInfo();
        DisplayMode dispMode = pntInfo.getDevice().getDisplayMode();
        int newX = new Random().nextInt( dispMode.getWidth() );
        int newY = new Random().nextInt( dispMode.getHeight() );
        new Robot( pntInfo.getDevice() ).mouseMove( newX, newY );
    } catch ( AWTException exception ) {  }
    

Sorry for my late answer ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top