Multiple functions with RButton (right click) conflicts

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mahrumer
Posts: 2
Joined: 04 Jun 2023, 08:15

Multiple functions with RButton (right click) conflicts

Post by mahrumer » 04 Jun 2023, 10:26

Hello guys, I'm trying to assign 4 actions to RButton (right click) but either one of the action never triggers or RButton's next menu shows up that I want to avoid if hotkey fired.

Global RButton Actions
- Right Click + Wheel Up/Down => Move to Left/Right Tab
- Right Click + Left Click => Close tab
- Right Click down and move mouse left/right => Switch Desktops

If any of above action triggers, do not show native right-click context menu

This is the closest I have been, but it always shows context menu once RButton is released.

Code: Select all

RButton::RButton ; needed to keep normal function of right click
	RButton & LButton::		SendInput, ^{w}
	RButton & WheelUp::	SendInput, ^+{Tab}
	RButton & WheelDown:: 	SendInput, ^{Tab}
	~RButton::
		xValue := 0
		yValue := 0  
		MouseGetPos, x, y
		While GetKeyState("RButton", "P")
		{
		  MouseGetPos, new_x, new_y
		  xValue := x - new_x
		  yValue := y - new_y
		  if(xValue != 0 & yValue != 0)
		  {
			if(xValue > 60 && xValue >= yValue && (yValue > -20 && yValue < 20))
			{
				SendInput, ^#{Left}

				sleep 150
				xValue := 0
				yValue := 0
				MouseGetPos, x, y
				
				continue
			}
			else if(xValue < -60 && xValue <= yValue && (yValue > -20 && yValue < 20))
			{
				SendInput, ^#{Right}
				
				sleep 150
				xValue := 0
				yValue := 0
				MouseGetPos, x, y
				
				continue
			}
		  }
		}
	return
I've tried controlling it with the variable but still it isn't' working properly, here is how it looks like

Code: Select all

#if GetKeyState("RButton", "P")

	isFired := false
	
	RButton::RButton ; needed to keep normal function of right click
	
	RButton & LButton::
		SendInput, ^{w}
		isFired := true
	return
	
	RButton & WheelUp::
		SendInput, ^+{Tab}
		isFired := true
	return
		
	RButton & WheelDown::
		SendInput, ^{Tab}
		isFired := true
	return
	
	~RButton::
		xValue := 0
		yValue := 0  
		MouseGetPos, x, y
		While GetKeyState("RButton", "P")
		{
		  MouseGetPos, new_x, new_y
		  xValue := x - new_x
		  yValue := y - new_y
		  if(xValue != 0 & yValue != 0)
		  {
			if(xValue > 60 && xValue >= yValue && (yValue > -20 && yValue < 20))
			{
				SendInput, ^#{Left}
				isFired := true

				sleep 150
				xValue := 0
				yValue := 0
				MouseGetPos, x, y
				
				continue
			}
			else if(xValue < -60 && xValue <= yValue && (yValue > -20 && yValue < 20))
			{
				SendInput, ^#{Right}
				isFired := true
				
				sleep 150
				xValue := 0
				yValue := 0
				MouseGetPos, x, y
				
				continue
			}
		  }
		}
		
		if(!isFired) {
			; somehow, suppress right-click context menu
		}
		
	return
#if
If I remove the last action (i.e. RButton down and move mouse left/right) everything else works fine without showing context menu.

Thanks in advance for the help & reading this question.

Rohwedder
Posts: 7623
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Multiple functions with RButton (right click) conflicts

Post by Rohwedder » 05 Jun 2023, 01:16

Hallo,
try:

Code: Select all

RButton & LButton::SendInput, ^{w}
RButton & WheelUp::SendInput, ^+{Tab}
RButton & WheelDown::SendInput, ^{Tab}
~RButton::
xValue := 0
yValue := 0
MouseGetPos, x, y
While GetKeyState("RButton", "P")
{
	MouseGetPos, new_x, new_y
	xValue := x - new_x
	yValue := y - new_y
	if(xValue != 0 & yValue != 0)
	{
		if(xValue > 60 && xValue >= yValue && (yValue > -20 && yValue < 20))
		{
			SendInput, ^#{Left}
			sleep 150
			xValue := 0
			yValue := 0
			MouseGetPos, x, y
			continue
		}
		else if(xValue < -60 && xValue <= yValue && (yValue > -20 && yValue < 20))
		{
			SendInput, ^#{Right}
			sleep 150
			xValue := 0
			yValue := 0
			MouseGetPos, x, y
			continue
		}
	}
}
SendInput,% (A_ThisHotkey="~RButton")?"":"{Esc}"
return

mahrumer
Posts: 2
Joined: 04 Jun 2023, 08:15

Re: Multiple functions with RButton (right click) conflicts

Post by mahrumer » 05 Jun 2023, 08:12

Hello @Rohwedder, Thanks, your solution gave me some really good ideas. I was able to achieve all 4 actions and also able to optimize it well with low CPU usage as it only invokes only if RButton is down. :D

Thank you so much. Here's the updated script future reference.

Code: Select all

#if GetKeyState("RButton", "P")

	~RButton & WheelUp::
		SendInput, ^+{Tab}
		allowRightClick := false
		sleep 100
	return
	
	~RButton & WheelDown::
		SendInput, ^{Tab}
		allowRightClick := false
		sleep 100
	return

	~RButton & LButton::
		SendInput, ^{w}
		allowRightClick := false
		sleep 10
	return
	
	RButton::
		actionTriggered := false
		allowRightClick := true
		MouseGetPos, x, y
		
		While GetKeyState("RButton", "P")
		{
			MouseGetPos, new_x, new_y
			xValue := x - new_x
			yValue := y - new_y  

			if(xValue != 0 & yValue != 0)
			{
				; switch desktops
				if(xValue > 100 && xValue >= yValue && (yValue > -20 && yValue < 20))
				{
					SendInput, ^#{Left}
					actionTriggered := true
					sleep 100
				}
				else if(xValue < -100 && xValue <= yValue && (yValue > -20 && yValue < 20))
				{
					SendInput, ^#{Right}
					actionTriggered := true
					sleep 100
				}
				
				if(actionTriggered) {
					MouseGetPos, x, y
					actionTriggered := false
					allowRightClick := false
				}
			}
		}
		if(allowRightClick) {
			SendInput, {RButton}
		}			
	return
#if

Post Reply

Return to “Ask for Help (v1)”