Mouseclick command doesn't check if mouse is already pressed when activating

Report problems with documented functionality
taltamir
Posts: 3
Joined: 14 Oct 2017, 07:46

Mouseclick command doesn't check if mouse is already pressed when activating

14 Oct 2017, 08:01

Lets say I have two browser pages set side by side. on the left side I have an open page that I automated via an AHK script that uses mouseclick every now and then (about 10 minutes)
On the right side I am actively doing something.

If the click on the left page happens while I am holding down the mouse button on the right page for some reason (typically, because I am clicking something at the moment, yes even though a click is fast, it is still long enough to cause this issue). than it will effectively drag my current page over from the right page to the left page. causing the browser on the left to navigate away to the same address as the page on the right.

Over the last few days it happened to me many times. with multiple sites.

I think the solution would be to do a check to see if the mouse is currently clicked and if it is then delay or skip. Maybe default to skip with an option to change behavior to wait instead

A similar issue is if I happen to be moving the mouse when AHK tries to click a spot. Because I am actively moving the mouse when AHK triggers, AHK will often miss the the spot it is programmed to click.

For that the solution would be to check to see if the mouse is currently moving. and again, either skip or wait. and/or have the mouse input be disabled, execute the command, and then reenable mouse input.

Honestly, mouseclick (not mousemove) should probably also automatically record the current location and then return to it when its done clicking before reenabling user mouse control.
User avatar
Exaskryz
Posts: 2603
Joined: 17 Oct 2015, 20:28

Re: Mouseclick command doesn't check if mouse is already pressed when activating

14 Oct 2017, 15:07

I think it offers more flexibility for a command to not make the assumptions you'd like here. All of this can be addressed by AHK anyway, and use conditional If statements to decide to do an action or not. As such, I do not believe this is a bug at all. Does the AHK documentation suggest the command should behave differently than what you are seeing? MouseClick.

As is, this topic seems more like a help request. Hopefully this information helps you:

If GetKeyState("LButton","D") should check if the user is doing a left click at the moment.

As for mouse moving, that's a lot trickier. You can try to capture the mouse position with MouseGetPos and then a split second later check it again and see if they differ. And if they do not, I would then recommend using BlockInput to prevent the user from interacting with the mouse when the MouseClick command is being executed. (There is still the slight possibility the user can click before the BlockInput command, so then combine with the above check.)

But the same point of returning to the starting location can be done by using MouseGetPos, then MouseClick, then MouseMove.

You may however be interested in using ControlClick. This basically tells the target window a click happened, without "hijacking" the mouse cursor.
taltamir
Posts: 3
Joined: 14 Oct 2017, 07:46

Re: Mouseclick command doesn't check if mouse is already pressed when activating

17 Oct 2017, 07:47

I have only made two assumptions
1. That if giving the command "click at coordinate x,y" you want it to actually be x y and not some other coordinate.
2. That when sending the command "left click", and not a drag and drop command (which exists), then you want it to perform a left click as explicitly ordered it to.

Not a "left click 99% of the time, but sometimes drag and drop instead and sometimes misclick". The fact that it is unreliable on when it performs what is the crux of the issue. If someone wants to perform a drag and drop, they would actually tell AHK to drag and drop and not to perform a left click while hoping they can synchronize their manual clicking with it.

I believe both of these are very reasonable assumptions. and there are no situations where they are false. Nor does ensuring they happen detract from the flexibility of the command.

I also specifically suggested that my ideas be implemented in the form of option. With the a logical default, but the ability to change it (or turn it off).

In regards to controlclick, I don't find it useful since it is too dependent on specific windows, and I need something that handles the whole screen without any regard to which window something appears in.

Thank you for pointing out "If GetKeyState("LButton","D")" to me, I will use it to program a manual check for such a thing.
However, even though this "resolves" my own issue, it is definitely an implementation error that it is not performed by default, or even as an option one could toggle to. Since without it the default state is that mouseclick is unreliable and inconsistent.

edit, here is my script below before adding in the "if getkeystate" thing.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

taltamir
Posts: 3
Joined: 14 Oct 2017, 07:46

Re: Mouseclick command doesn't check if mouse is already pressed when activating

17 Oct 2017, 08:52

Exaskryz wrote:If GetKeyState("LButton","D") should check if the user is doing a left click at the moment.

Thank you for the suggestion. After some testing and then reading through the documentation, I found out that it needs to be



the D and U are used in a different syntax, in the syntax you used it in, you can either send "P" (checks for physical clicks) or "T" (check OS toggle state). Putting a D there is a mistake. leaving it blank is fine too (defaults to T).

It also needs to have a not or ! because the result is "true" if the button is clicked. and I only want to perform an action if the button is not clicked, so I need it to be false. hence the ! to switch the result of that function.

Or even better, make my own function that calls on getkeystate in order to verify none of the mouse button are pressed (left, right, and middle)

Here is my tested to be working code which integrates that line in case someone wants to use it

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
Exaskryz
Posts: 2603
Joined: 17 Oct 2015, 20:28

Re: Mouseclick command doesn't check if mouse is already pressed when activating

17 Oct 2017, 10:46

In regards to my typo on the GetKeyState() function, yep, I meant to put P. (Typing this out, I Typed "I meant to put D"... which again was wrong. I really mean P.) So apologies on that. And it is true the ! would be necessary depending on how you wanted to handle the logic.

I don't think the assumptions you made are entirely infallible. There may be some creative minds that may want to have some kind of drag to their command. I think they're reasonable assumptions, but again there are methods for forcing the clicks to behave differently to match your expectations. If you think these should be options, can you describe how they should be implemented or what syntax you envision? And actually, can you describe what that second assumption really means?

I noticed your code uses Click, not MouseClick. MouseClick has a speed parameter which may be of interest.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 3 guests