java console mouselistener

旧城冷巷雨未停 提交于 2019-12-02 00:17:25

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.

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 ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!