Gui button-Left or Right Click Variables-Ctrl+Click? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Arempi
Posts: 18
Joined: 22 Dec 2017, 20:01

Gui button-Left or Right Click Variables-Ctrl+Click?

17 Jan 2018, 21:06

Is there an easy way to add Left Click and Right Click functionality to a gui button? (or CTRL+Left click)
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Gui button-Left or Right Click Variables-Ctrl+Click?  Topic is solved

17 Jan 2018, 22:10

Hi Arempi,

If it is question of the LButton specify a g-label the moment you create the control, otherwise, to monitor the RButton click event specify a GUIContextMenu label - simple example:

Code: Select all

#NoEnv
#Warn
SendMode Input
#SingleInstance force
; Windows 8.1 64 bit - Autohotkey v1.1.27.04 32-bit Unicode

Gui, Add, Button, gsubroutine w300 h50, OK
Gui, Show, AutoSize
return

subroutine:
MsgBox % A_ThisLabel
return

GuiContextMenu:
MsgBox % A_ThisLabel
return
If it is question of a specific button and in case you want to use Ctrl+Click as hotkey, you can also use a context-sensitive hotkey (#If function, the latter function using MouseGetPos to determine whether or not the mouse is over a specific button the moment RButton is pressed):

Code: Select all

#NoEnv
#Warn
SendMode Input
#SingleInstance force
; Windows 8.1 64 bit - Autohotkey v1.1.27.04 32-bit Unicode

; menu -----------------------------------------------------------------
Menu, MyMenu, Add, Item1, MenuHandler
try Menu, MyMenu, Icon, Item1, imageres.dll, 1
Menu, MyMenu, Add
Menu, MyMenu, Add, Item2, MenuHandler
try Menu, MyMenu, Icon, Item2, imageres.dll, 2
; GUI -----------------------------------------------------------------
Gui, Add, Edit, w200, OK
Gui, Add, ListBox, w200, OK
Gui, Add, Button, hwndCID w200, OK ; 'hwndCID' stores the window handle (HWND) of the control in 'CID'
Gui, Show, AutoSize
return


#If mouseIsOverControl(CID)
^RButton::Menu, MyMenu, Show
#If

MenuHandler:
MsgBox % A_ThisMenuItem
return
mouseIsOverControl(__controlID) {
    MouseGetPos,,,, __outputVarControl, 2 ;  stores the control's HWND in '__outputVarControl'
return (__outputVarControl = __controlID)
}


Hope this helps.
my scripts
Arempi
Posts: 18
Joined: 22 Dec 2017, 20:01

Re: Gui button-Left or Right Click Variables-Ctrl+Click?

18 Jan 2018, 02:23

A_AhkUser,

Perfect!... I needed to have the ability to send two different routines (currently) per button. I did not think to add contextmenus for further options - great idea. I'm still learning ahk, working on my first program/script. 640 lines so far. There is probably better ways to accomplish most of the functions. lol.

Don't understand some of this, but enough to get me started!
I appreciate the help! ~Arempi

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, Google [Bot], mikeyww, TAC109 and 379 guests