java console mouselistener
-
30-09-2019 - |
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.
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:
- http://kra.lc/blog/2011/07/java-global-system-hook/
(works well - I would advice to re-indent the c++ content and if you know how to do, merge it into 1-2 files - your eyes will thank you) - http://www.jotschi.de/Technik/2008/01/06/java-global-keyboard-hook-jni.html
(never tried, but looks more simple)
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