I want to write a program which can control my cursor movements depending on the the way I move my finger on the touchpad. I want my program to get the location where the user touched the touchpad, then I want to control mouse movement using my own program. I want do this in Java. Can I do this in Java? I would like to run it on Windows OS. Does my laptops touchpad device driver provide some API by which I can get the info about when and where the user touched the touchpad?
Think about this situation.
Person wants to exit your program. They touch the trackpad. Your program moves the cursor somewhere they didn't expect. They're upset and confused.
They continue to touch the trackpad, your program continues to do something they didn't expect. They find they're unable to control the cursor. Now what?
Generally, having your program move the cursor is a recipe for disaster.
The cursor is hard enough to spot on the screen. X-windows applications which do "cursor warping" to dialog boxes have an option to disable this because it is confusing.
Removing control of the cursor from the user makes the computer (already very hard to use) much harder to use because there's this "mode" thing. When your program is running, one thing happens. When your program is not running, something different happens.
Look at http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Cursor.html
There do not appear to be any methods to change the cursor's position. It tracks the mouse.
However, look at http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Robot.html
This has the ability to synthesize mouse events. Feel free to play with it.
Related
I want to make a program that recognize a button that is in the League of Legends client, and when the queue's button shows up the mouse instantly click on it.
Its a sort of a AutoAccept Client...
There is already a program that someone did, but it has so many unnecessary things and it does not work very well....
How do I do to recognize a element inside a program to make my mouse move there when it shows up?
I can try to code this in any language, just gimme a tip pls
You can create a program that takes a screenshot every 100ms, use a recognition algorithm of your choice and then (optionally) performs a mouse click. There are enough libraries that can screenshot for you, you should be able to recognise the button by colour and location and every language should have some method of controlling the mouse.
Sikulix (can be paired with python) is a perfect tool to use for this. It scans over your screen constantly, and if the image in question pops up (the accept button) you can click on it.
You will have to take a screenshot and likely store it as .png so the program knows what it is looking for.
Google Sikulix.
I'm fluent in java, and have messed with vb.net, but I prefer java. I wish to make a program that ++'s a variable everytime I click my mouse in a certain coordinate on my screen. Not sure how to record when a mouse click has happened outside of the program's forms.
This can't be done in pure Java but people have written JNI libraries that can capture global mouse and keyboard events. Take a look at
https://github.com/kwhat/jnativehook
I have to display x,y coordinate values on mouse pointer tooltip. The text should follow the mouse pointer. How can this be done.
From an rcp application, I will click a button, then application will be minimized. Then wherever (on desktop/other application) I move the mouse pointer, it should display some text attached to mouse. I know how to find the coordinates of mouse pointer location, but I want to display those values in mouse pointer tool tip.
Any thoughts.
Unfortunately, what you are asking can't be done in SWT. The only way to do this, and communicate/control it through a Java/Eclipse/SWT app, would be through the Java Native Interface (JNI). You could write a native program (in C++, for example, for a specific OS) to monitor the cursor and change its image as it moves across the screen. You can also pipe data from that native program to your java app. But that is a whole 'nother world beyond Java.
SWT can only manage the cursor over a specific SWT control. Not outside of a SWT control, on the desktop or over another app's windows.
Now, if you could settle for having, say a small dialog/window open (via your application), perhaps tucked in the corner of the screen (rather than at the mouse cursor), that shows the current mouse position that could be done. You'd have to have a process/thread running in the background that would monitor the current screen mouse position, via:
display.getCursorLocation();
Basically the runnable in the process/thread would simply be in an infinite loop and reading the cursor location, then updating the x,y coords in the "output box."
As an extension to this, you could have a small, bare-bones SWT shell that "follows" the cursor around during the cursor read in the thread. You would simply update the location of the shell based on the current cursor location, and set text in that window (a nested Text control) to the appropriate coordinates. Of course, I don't know how "clean" that would appear, as I haven't tried it. But that's about the best you can do in SWT without JNI.
But in these methods you wouldn't be changing the actual cursor/image.
Hope that helps.
In Java, how can I measure the speed of the mouse movement but disable the actual cursor movement. For example, when someone swipes their mouse across a table, I want to measure how fast he/she swiped the mouse without the cursor actually moving.
I've tried doing this by resetting the mouse position to a specific coordinate (robot class) but the mouse is able to escape when I swipe really fast.
If this is not possible in Java, a C# or C++ solution would be okay.
Thanks
if you really want to block mouse movement events you'd need to do it much lower - in c/c++ at the input filter layer. here's a question to point you in the right direction: Blocking mouse input from a service in Vista
might be possible using autohotkey (which does a lot of the nitty-gritty stuff for you)
It depends on the operating system but for Windows you could try using Input Hooks. I have had to use this before and it works. The solution is a little complex because you have to write a dll which provides a function address which you can insert in to the input hook chain in Windows. This is essentially what autohotkey does, but they give a very nice scripting interface and they do all the heavy lifting of setting up the various dlls and Win32 calls on your behalf. In case you are curious about input hooks: Hooks Overview
I've been playing with the Robot class recently and I have it doing what I want, but I haven't figured out how to interrupt/stop its actions via user input.
For example: I want it to click the desktop a hundred times but I decide forty clicks in that I want to make it quit (or pause).
I'd like to be able to do something simple like press a certain key or press the middle mouse button in order to tell it to stop. In order to do this, it must be able to listen for input outside of the Java application, since the actions the Robot is performing are in other programs.
As edward said, there doesn't seem to be a way to do exactly what I was looking for. So this answer is to explain how I achieved an acceptable substitute.
The other question edward linked to had stated that
MouseInfo.getPointerInfo().getLocation()
is capable of fetching the mouse coordinates regardless of what the mouse is doing. My program uses the robot class to control the mouse within a specific range of coordinates. I also wanted to be able to disable the program via user input.
To achieve this result, I compared the x and y coordinates of the mouse to the x and y coordinates that the robot last set it to. If the two do not match, the program exits.
Pausing the program by this method would be impractical because resuming would require going back to the original x and y coordinate prior to pausing, but it does at least give an example of how to achieve stopping without actually being focused on the java parent program.
In order to pause the program, you would instead compare the coordinates to a range of coordinates (have the coordinates create an imaginary, 2D box). If the mouse's coordinates are within that range: pause. To resume, do the opposite check (mouse not being in that range).
You may be able to use some of the code from this answer:
Simulate a key held down in Java
And then add a Listener to whatever action, component, whatever to call the stop method on the robot command.
Does that provide you with some inspiration?
Edit After further discussion the real question is:
How to respond to external Mouse Events (Outside the Java Application) inside a Java application?
It Seems that you can't without native code and Mouse Hooks as it's OS Dependent.
For Further Discussion see Is it possible to have a MouseMotionListener listen to all system mouse motion events?