Send {RButton} interferes with my mouse gestures Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
BurrowBird
Posts: 31
Joined: 20 Jul 2020, 11:25

Send {RButton} interferes with my mouse gestures

14 Sep 2020, 09:24

In Chrome I use an extension called smartUp Gestures, where if I hold down RMB and drag left down for example the current tab closes and so on.

Then I want to have this script active for something unrelated:

Code: Select all

RButton::Send {RButton}
RButton & LButton::Send s
But now I can't drag with RMB. Similar issue would be with the left mouse button, where this script disables selecting things with LMB which is even worse.

Is there a way to make it so that the mouse drag inputs are coming through? I feel like I'm missing something basic. :cry:

Thank you!
User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Send {RButton} interferes with my mouse gestures

14 Sep 2020, 09:31

You could try preceding the hotkey with a tilde (~), to see if that works. Tilde lets the hotkey go through before executing the AHK code.

Code: Select all

~RButton::MsgBox, I actually issued a button press and did not just trap it.
BurrowBird
Posts: 31
Joined: 20 Jul 2020, 11:25

Re: Send {RButton} interferes with my mouse gestures

14 Sep 2020, 09:43

mikeyww wrote:
14 Sep 2020, 09:31
You could try preceding the hotkey with a tilde (~), to see if that works. Tilde lets the hotkey go through before executing the AHK code.
Like so?

Code: Select all

~RButton & LButton::Send s
Thank you. Hovewer, If I do that, then my "s" script stops working because a RMB context menu interrupts it. There, I need to send "s" only, without any RButton. But I still need RButton to work normally, so I send it:

Code: Select all

RButton::Send {RButton}
But I also need RMB dragging to still work which this line seems to mess with, which is the real issue.
User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Send {RButton} interferes with my mouse gestures

14 Sep 2020, 10:05

Well, I don't think you want to send "s" while you are actually dragging the mouse, so perhaps you want to toggle your customized hotkey at particular times. You could enable a toggle by using the Hotkey command to enable or disable the hotkey according to your situation.

https://www.autohotkey.com/docs/commands/Hotkey.htm
BurrowBird
Posts: 31
Joined: 20 Jul 2020, 11:25

Re: Send {RButton} interferes with my mouse gestures

14 Sep 2020, 10:37

That works, but I tend to use both mouse dragging and the "s" hotkey in close proximity. Turning the hotkey on and off is too annoying in this case.

I would really love to have the script always running in the background and not interfere with mouse dragging. :think:

I feel like there should be a way around this since using mouse hotkeys messing with dragging should be a common issue, right? I'll keep searching.

Alternatively, if I scripted the same behaviour my Chrome gesture extension offers in AHK then there should be no conflict I guess, but I have no clue how to do that or if it's possible yet. I would need to get AHK to check if I moved the mouse in a certain direction. :/
User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Send {RButton} interferes with my mouse gestures

14 Sep 2020, 10:54

One clunky workaround is to run a timer that frequently identifies the mouse position, and activates your hotkey if the mouse is not on the tab bar. It would work, but I can't exactly recommend it!

Other ideas that sort of go in a different direction: use a different hotkey? Set a hotkey to close your tab instead of using RButton?
BurrowBird
Posts: 31
Joined: 20 Jul 2020, 11:25

Re: Send {RButton} interferes with my mouse gestures

14 Sep 2020, 11:14

Well... since sending RButton in AHK disables mouse dragging, and I also can't use "~" because it breaks my hotkey, I'm in a pinch.

What I ended up doing is setting a "button-chording" (as they call it) in a software called X-Mouse Button Control, which acts as a

Code: Select all

RMB+LMB -> s
hotkey. Basically it does the same thing I would love my AHK script to do, but without messing with mouse dragging. I didn't want to involve other programs in my solution, but I can't find any more clues in the AHK docs or here.. :/

EDIT: While searching the forum, I found a reference to "while-loops with GetKeyState inside" as a method to help with dragging the mouse. I shall investigate.
User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Send {RButton} interferes with my mouse gestures

14 Sep 2020, 11:25

From your previous code, what happens if you just delete the first line?

Code: Select all

; RButton::Send {RButton} ; Delete this line
RButton & LButton::Send s
BurrowBird
Posts: 31
Joined: 20 Jul 2020, 11:25

Re: Send {RButton} interferes with my mouse gestures

14 Sep 2020, 11:44

Chrome doesn't recognize mouse dragging with RMB anymore. I think the problem lies in the way hotkeys with & work. It makes the mouse button not pressed down while dragging.

For example, I found that:

Code: Select all

RButton::
SendInput {RButton down}
KeyWait RButton
SendInput {RButton up}
return
works, in that it manages to send RMB through but I can still drag the mouse as normal. Similar working script is this:

Code: Select all

RButton::
	sendinput {RButton down}
	while GetKeystate("RButton","P")
		{
		sleep 50
		}
	sendinput {RButton up}
	return
However, this kind of code:

Code: Select all

RButton & LButton::
	SendInput {RButton down}
	KeyWait RButton
	SendInput {RButton up}
	return
makes it such that dragging is no longer recognized. I think the first key in a hotkey combination might be locked until it's released (but not held), then it is sent upon release no matter the code that follows or something like that..?

EDIT: Ideally, I would like to use ~RButton here to make sure I can still drag, but not actually send any RButton, if that makes sense. :D

EDIT EDIT: Alternatively, if there is a way to detect if "s" was sent recently, I could perhaps use that somehow. Can you do {RButton up} but hide it from Windows? As in, if "s" was sent recently, I want RButton to be not held anymore, but I don't want to send it (to prevent the context menu to pop up).
User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Send {RButton} interferes with my mouse gestures

14 Sep 2020, 12:16

Not sure! You can always trap "s" and run an expiration timer, but not sure if all of that code is worthwhile. Up to you.
BurrowBird
Posts: 31
Joined: 20 Jul 2020, 11:25

Re: Send {RButton} interferes with my mouse gestures  Topic is solved

14 Sep 2020, 12:30

"Trap" it? Not familiar with that. As in stall it a bit? I need it to fire before RMB though is the thing. I would rather like to time out or get rid of "RButton up" if possible...

Code: Select all

RButton & LButton::
	Send s
	SendInput {RButton down}
	KeyWait LButton
	SendInput {LButton up}
	Sleep, 50
	SendInput {RButton up}
	return
This sort of almost works kinda. The hotkey works since the context menu doesn't get in the way (it's delayed by Sleep), but then it gets sent anyway so it's annoying. :/

EDIT: So this code:

Code: Select all

RButton::		
	SendInput {RButton down}
	KeyWait RButton
	SendInput {RButton up}
	return

RButton & LButton::
	SendInput {RButton down}
	KeyWait LButton
	SendInput {RButton up}
	Send {Escape}
	Sleep 300
	Send s
	return
is kinda a dumb workaround, but it does work for me. What I did is just get rid of the context menu with Escape, then send the "s" without it in the way. Sleep makes it work consistently.

EDIT EDIT: Actually does not work. Did something change or did I forget to check before going to dinner? The dragging doesn't work still with this code! :headwall:

EDIT EDIT EDIT: Actually now that I got rid of the context menu (using Escape lol), I can use the tilde again! So it does work after all, though it's a clunky workaround still.

This is what I have now (no need for "RButton::" now that I have the tilde):

Code: Select all

~RButton & LButton::
	SendInput {RButton down}
	KeyWait RButton
	SendInput {RButton up}
	SendInput {Escape}
	Sleep 300
	Send s
	SendInput {Escape}
	return
Last edited by BurrowBird on 14 Sep 2020, 13:51, edited 5 times in total.
User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Send {RButton} interferes with my mouse gestures

14 Sep 2020, 12:37

I just mean that you could set a hotkey for "s", or use an Input or KeyWait, but I don't necessarily recommend doing that-- can cause other problems down the road.
BurrowBird
Posts: 31
Joined: 20 Jul 2020, 11:25

Re: Send {RButton} interferes with my mouse gestures

14 Sep 2020, 12:40

Well my hotkey for "s" is RMB+LMB. That is what causes the problem, because AHK obviously has severe quirks with handling these.
User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Send {RButton} interferes with my mouse gestures

14 Sep 2020, 12:51

Perhaps someone else has a solution.
BurrowBird
Posts: 31
Joined: 20 Jul 2020, 11:25

Re: Send {RButton} interferes with my mouse gestures

14 Sep 2020, 13:16

Perhaps. Thank you for your help, you guided me in the right direction!

Also now that I think of it, I feel like intuitively all of my scripts should have worked, since "s" is always sent first before RMB is released. But for some reason the context menu seems to pop up first, before the "s" and messes things up.
It might be a Windows thing - it puts high priority on RMB and snaps it in front of other stuff, unless I divorce the inputs far enough with sleeps or timers.
User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Send {RButton} interferes with my mouse gestures

14 Sep 2020, 13:20

Yes, if you are sending RButton to the browser, then expect the context menu to appear! 8-)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: haomingchen1998, mikeyww, ReyAHK and 263 guests