Page 1 of 1

Looking for a Right Mouse to Middle Mouse Hold Script

Posted: 20 Sep 2019, 01:49
by HenryCAD
Hey,

I'm new here and I have no idea about scripting. I'm a CAD user, using SolidWorks. I don't like to hold middle mouse (wheel) to orbit inside the software. So I am looking for a script, that do the following:

When I just press and release the right mouse button -> make a normal right mouse button press and release.

But when I hold the right mouse button and also start to move my mouse courser -> simulate that I hold the mittle button.

I have googled for scripts like this but I did not found anything like it. I found similar scripts, so I think it could be possible. But with no idea about coding I was not able to create my own script. I hope someone can help me out. Thank you all in advance.

Greetings,

Henry

Re: Looking for a Right Mouse to Middle Mouse Hold Script

Posted: 20 Sep 2019, 02:04
by ilhom
The middle mouse button will trigger if you hold down the right mouse button for 200ms. You can increase this time by changing T0.2 to a higher value.

Code: Select all

$RButton::
keywait, RButton, T0.2
    if (Errorlevel = 1)
	{
		Click, down, Middle
		KeyWait, RButton
		Click, up, Middle
	}
	else
		Click, Right

Re: Looking for a Right Mouse to Middle Mouse Hold Script

Posted: 20 Sep 2019, 02:07
by HenryCAD
Wow... that was fast! And it works like a charm. Thank you very much!

Edit: I can not use the CTRL modifier with this script. So, If I press CTRL + hold right button, I don't get the CTRL + middle mouse hold. Is there a way to fix it? I can live without it, but it would be the cherry on top. :D

Edit 2: I do not know if it makes sense, but I've tested some things an this seem to work

Code: Select all

^RButton::
SendInput {RButton Down}

$RButton::
keywait, RButton, T0.2
    if (Errorlevel = 1)
	{
		Click, down, Middle
		KeyWait, RButton
		Click, up, Middle
	}
	else
		Click, Right
Edit 3: It does not work. :(

Edit 4: I've tried this but I get an unwanted right click when I release the RButton Hold

Code: Select all

$RButton::
keywait, RButton, T0.2
    if (Errorlevel = 1)
	{
		Click, down, Middle
		KeyWait, RButton
		Click, up, Middle
	}
	else
		Click, Right


$^RButton::
keywait, RButton, T0.2
    if (Errorlevel = 1)
	{
		Click, down, Middle
		Click, down, CTRL
		KeyWait, RButton
		Click, up, Middle
		Click, up, CTRL
	}
	else
		Click, Right

Re: Looking for a Right Mouse to Middle Mouse Hold Script

Posted: 23 Sep 2019, 01:42
by HenryCAD
Maybe someone else has a solution to my problem? Otherwise, I leave it here and I'm glad that it works almost as well as I wanted. :)

Re: Looking for a Right Mouse to Middle Mouse Hold Script

Posted: 23 Sep 2019, 03:35
by YoucefHam
Try this

Code: Select all

;Change acad.exe with your software name
#IfWinActive ahk_exe acad.exe



$RButton::
keywait, RButton, T0.150
if Errorlevel
{
	Send, {MButton Down}
	KeyWait, RButton, L
}
else
	Send, {RButton}
return


$RButton Up::
Send, {MButton Up}
return

Re: Looking for a Right Mouse to Middle Mouse Hold Script

Posted: 23 Sep 2019, 05:21
by HenryCAD
Thanks for your help. Unfortunately your script works exactly like ilhom's (missing the CTRL modofier function). Just to make sure that there are no misunderstandings, here are the things that I asked for:

When I single click RButton -> normal RButton click (works fine with both scripts)
When I hold RButton -> simulate MButton hold (works fine with both scripts)
When I press CTRL + hold RButton -> send CTRL + hold MButton (does not work with both scripts)

Re: Looking for a Right Mouse to Middle Mouse Hold Script

Posted: 23 Sep 2019, 05:32
by YoucefHam
try this

Code: Select all

;Change acad.exe with your software name
#IfWinActive ahk_exe acad.exe



*$RButton::
keywait, RButton, T0.150
if Errorlevel
{
	Send, {MButton Down}
	KeyWait, RButton, L
}
else
	Send, {RButton}
return


$RButton Up::
Send, {MButton Up}
return

Re: Looking for a Right Mouse to Middle Mouse Hold Script

Posted: 23 Sep 2019, 06:36
by HenryCAD
Does not work either.

With you first script I've got a normal right click wehen using the CTRL modifier. With the new script I've got the hold Mbutton, but CTRL does not got recognized.

Re: Looking for a Right Mouse to Middle Mouse Hold Script  Topic is solved

Posted: 23 Sep 2019, 16:30
by ilhom
HenryCAD wrote:
23 Sep 2019, 06:36
Does not work either.

With you first script I've got a normal right click wehen using the CTRL modifier. With the new script I've got the hold Mbutton, but CTRL does not got recognized.
Adding the wildcard to my original should do what you're asking. This will also work with alt, shift, etc.

Code: Select all

$*RButton::
keywait, RButton, T0.2
    if (Errorlevel = 1)
	{
		Click, down, Middle
		KeyWait, RButton
		Click, up, Middle
	}
	else
		Click, Right