Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Modified Middle Click Simulator


  • Please log in to reply
6 replies to this topic
surlacarte
  • Guests
  • Last active:
  • Joined: --
I recently found the following AutHotkey script for adding a middle click to a two button mouse by pushing the left and right mouse buttons simultaneously:

~LButton & RButton::MouseClick, Middle
~RButton & LButton::MouseClick, Middle

The script is successful in producing a middle click, but because the ~ preserves the native function, it has the unintended consequence of also generating a left or right click. This is rather annoying, since I use it mainly for tabbed browsing, so half the time, when I try to open a link in a new tab, I also open it in the original tab.

I've been trying desperately to tweak it, but have had no success. I tried the suggestion here to omit the tilde and define LButton and RButton separately, but this eliminates the ability to click and drag. Is there any way to keep the native function of each button EXCEPT when the other button is pressed? Or to interrupt the native function when the other button is pressed, so, for example, if I hold down the left button and press the right button, the release of the left button won't be registered as an event?

Alternatively, would it be possible to leave off the tilde and set the exact desired behavior of LButton and RButton in all cases, while preserving the ability to click and drag?

Any help would be greatly appreciated!

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Try this, does it work?
#Persistent

SetBatchLines, -1

Hotkey,LButton,LButton

Hotkey,RButton,RButton

Return

LButton:

Hotkey,RButton,MiddleClick

MouseGetPos,x,y

Loop{

	MouseGetPos,xn,yn

	If (x!=xn or y!=yn){

		Click, down

		break

	}

}

KeyWait,LButton

Click, up

Hotkey,RButton,RButton

Return



RButton:

Hotkey,LButton,MiddleClick

MouseGetPos,x,y

Loop{

	MouseGetPos,xn,yn

	If (x!=xn or y!=yn){

		Click, down right

		break

	}

}

KeyWait,RButton

Click, up Right

Hotkey,LButton,LButton

Return



MiddleClick:

Click,M

Return


surlacarte
  • Guests
  • Last active:
  • Joined: --
Thanks so much for the response. This almost works, but not quite. Click and drag works great, as does the middle click, but the left and right mouse buttons don't work right. Specifically, when you do a normal click with either button, it doesn't register until you move the mouse.

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
If you don't mind having to start the key combo with the right button, try this

Hotkey, $*LButton, off
Hotkey, $*LButton Up, off
SetMouseDelay, 0
$*RButton::
RightDown = 1
Hotkey, $*LButton, on
Hotkey, $*LButton Up, on
Keywait, MButton, LDT0.5 ; pressing the LButton within 0.5 seconds of pressing
; the RButton will remap the LButton to MButton until the RButton is released
If ErrorLevel
{
	Hotkey, $*LButton, off
	Hotkey, $*LButton Up, off
	Click, Right Down
	If !RightDown
		Click, Right Up
}
Else RightDown = 0
return
$*RButton Up::
Hotkey, $*LButton, off
Hotkey, $*LButton Up, off
If GetKeyState("MButton")
	Click, Middle Up
If (!RightDown) = (RightDown := 0)
	Click, Right Up
return
$*LButton::MButton


surlacarte
  • Guests
  • Last active:
  • Joined: --
I don't really mind having to initiate it with the right mouse button, but if it's going to do that and also disable click and drag with the right mouse button (which it does), I might as well just use this script:

RButton & LButton::MouseClick, Middle
RButton::Send {RButton}

Which, now that I mention it, maybe 90% solves my problem. I do use click and drag with the right mouse button, but not often, and I might be willing to sacrifice it. Thanks for inspiring a solution.

Still, if anyone thinks of a solution that doesn't involve disabling click and drag with the right mouse button, let me know.

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
Actually, the script I posted does not block right-mouse clickdrag. You just have to wait half a second for the down event to go through.

surlacarte
  • Guests
  • Last active:
  • Joined: --
I stand corrected! Thanks!