Different functions on RButton and LButton Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Logonius
Posts: 31
Joined: 19 Aug 2022, 08:20

Different functions on RButton and LButton

Post by Logonius » 04 Oct 2022, 00:43

Hello.
I can't figure out how to make my button in the GUI do one function when pressing LButton, and another when pressing RButton.

When adding RButton::, the function extends to the entire GUI and it works globally in windows, and I only need a button.

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

Re: Different functions on RButton and LButton

Post by Rohwedder » 04 Oct 2022, 01:19

Hallo,
in what gui? Reduce your script to the parts that don't behave as you want and show us.

Logonius
Posts: 31
Joined: 19 Aug 2022, 08:20

Re: Different functions on RButton and LButton

Post by Logonius » 04 Oct 2022, 01:29

Here is an example of how I can force Rbutton to perform a function only when my cursor is on the button and Rbutton is pressed.

When I click Rbutton, it works globally.

Code: Select all

Gui, Add, Button, gBut1 vButton3, Button

Gui, Show,  w100 h100
Return

But1:
MsgBox, hello1
return

RButton::
MsgBox, hello2
return

GuiClose:
ExitApp

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

Re: Different functions on RButton and LButton

Post by Rohwedder » 04 Oct 2022, 02:01

If the gui has the focus, then:

Code: Select all

Gui, Add, Button, gBut1 vButton3, Button

Gui, Show,  w100 h100
Return

But1:
MsgBox, hello1
return

#IFWinActive, ahk_class AutoHotkeyGUI
RButton::MsgBox, hello2
#IF

GuiClose:
ExitApp
Otherwise a global RButton-Hotkey could check with MouseGetPos over which window it is located.

Logonius
Posts: 31
Joined: 19 Aug 2022, 08:20

Re: Different functions on RButton and LButton

Post by Logonius » 04 Oct 2022, 03:07

maybe there are examples?, I read the help on MousesGetPost, but I didn't understand anything at all

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

Re: Different functions on RButton and LButton  Topic is solved

Post by Rohwedder » 04 Oct 2022, 04:09

Try:

Code: Select all

Gui, +HwndMyGui
Gui, Add, Button, gBut1 vButton3, Button
Gui, Show,  w100 h100
Return

But1:
MsgBox, hello1
return

GuiClose:
ExitApp

RButton::
MouseGetPos,,, Win, Control
IF (Win = MyGui) And (Control = "Button1")
	MsgBox, hello2
Else
	Click Right
Return

Logonius
Posts: 31
Joined: 19 Aug 2022, 08:20

Re: Different functions on RButton and LButton

Post by Logonius » 04 Oct 2022, 04:37

Thank you very much

Post Reply

Return to “Ask for Help (v1)”