Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse.click method throws exception with null location #299

Closed
midorimide opened this issue Jan 30, 2020 · 5 comments
Closed

Mouse.click method throws exception with null location #299

midorimide opened this issue Jan 30, 2020 · 5 comments
Assignees

Comments

@midorimide
Copy link

Hi!

There is a

protected static int click(Location loc, int buttons, Integer modifiers, boolean dblClick, Region region)

method in the Mouse class (247 line). It has check for necessity of mouse moving

...
boolean shouldMove = true;
if (loc == null) {
  shouldMove = false;
  loc = at();
}
...

Well, if the loc is null, mouse won't move. That is exactly what I want. However, when I'm trying to pass the null value to the

public static Location click(Location loc, String action, Integer... args)

method (Mouse class, 192 line), that calls previously mentioned protected method and can be called outside of this class, it throws java.lang.NullPointerException, because it immediately calls loc.isOtherScreen()

public static Location click(Location loc, String action, Integer... args) {
    if (get().device.isSuspended() || loc.isOtherScreen()) {
      return null;
    }
    ...

Should there be check for null?

@midorimide
Copy link
Author

Well, if the loc is null, mouse won't move. That is exactly what I want.

I mean, I don't want to send mouse move message to Windows, which i'm working with.

@RaiMan
Copy link
Owner

RaiMan commented Jan 30, 2020

Not really sure, what you want.

... but a possible null-parameter should be checked before used and throw an IllegalArgumentException to point at the problem (not only NPE).

Mouse.click() is intended to click at the given location.
Hence it must move before, if the current mouse pos is different.

If you want to click at the current position of the mouse pointer: Mouse.at()

@RaiMan
Copy link
Owner

RaiMan commented Jan 30, 2020

@midorimide
Copy link
Author

Not really sure, what you want.

I have next code

Mouse.click(Mouse.at(), "L");

When run it, if I'll hook Windows messages (posted by Windows after Sikulix has send input messages to it) , I receive MouseMove event, followed by MouseDown and MouseUp.
In other words, even if I'll click at the current cursor position, it leads to changing cursor's position to its current value and notifying Windows about it.
Is there some valuable reason to do this? My suggestion is to prevent sending mouse move input to the target OS, if the location is the same as cursor's. Something like modifying the

protected static int click(Location loc, int buttons, Integer modifiers, boolean dblClick, Region region)

method's code

...
boolean shouldMove = true;
if (loc == null) {
    shouldMove = false;
    loc = at();
}
else {
    if (loc.equals(at())) {
        shouldMove = false;
    }
}
...

The reason to do it is to prevent confusing, because it is unexpected that mouse will move when clicking at its current position.

@RaiMan
Copy link
Owner

RaiMan commented Jan 30, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants