Click Action on GUI Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Spark
Posts: 80
Joined: 04 Jan 2017, 02:22

Click Action on GUI

24 May 2018, 21:14

Hello..
is there a way to make every click command on a GUI?
Left click working, but how about Right Click and Middle click??
thanks in advance.

Code: Select all

Z1 = C:\Program Files\AutoHotkey\AutoHotkey.exe
Z2 = C:\Program Files\AutoHotkey\AU3_Spy.exe
Gui, 8:Add, Picture, x5 y5 w50 h50 gPic1, %Z1%
Gui, 8:Add, Picture, xp+75 y5 w50 h50 gPic2, %Z2%
Gui, 8:Show
OnMessage(0x200, "HelpTip")
return

8GuiEscape:
8GuiClose:
    ExitApp

Pic1:
MsgBox, Left Click on Picture 1
return
Pic2:
MsgBox, Left Click on Picture 2
return


HelpTip(wParam, lParam, Msg) {
	global Z1,Z2
MouseGetPos,,,, OutputVarControl
IfEqual, OutputVarControl, Static1
	HelpTip := Z1
else IfEqual, OutputVarControl, Static2
	HelpTip := Z2
ToolTip % HelpTip
}
AHKd00b
Posts: 10
Joined: 16 May 2018, 16:12

Re: Click Action on GUI  Topic is solved

24 May 2018, 23:09

You're welcome in advance :crazy:

Code: Select all

Z1 = C:\Program Files\AutoHotkey\AutoHotkey.exe
Z2 = C:\Program Files\AutoHotkey\AU3_Spy.exe
Gui, 8:Add, Picture, vPic1 gcase x5 y5 w50 h50, %Z1%
Gui, 8:Add, Picture, vPic2 gcase xp+75 y5 w50 h50 , %Z2%
Gui, 8:Show

OnMessage(0x0201, "WM_LBUTTONDOWN")
OnMessage(0x0207, "WM_MBUTTONDOWN")
OnMessage(0x0204, "WM_RBUTTONDOWN")

case:
	return

WM_LBUTTONDOWN() {
	if A_GuiControl = Pic1
		gosub Pic1L
	else if A_GuiControl = Pic2
		gosub Pic1L
}

WM_RBUTTONDOWN() {
	if A_GuiControl = Pic1
		gosub Pic1R
	else if A_GuiControl = Pic2
		gosub Pic1R
}

WM_MBUTTONDOWN() {
	if A_GuiControl = Pic1
		gosub Pic1M
	else if A_GuiControl = Pic2
		gosub Pic1M
}

8GuiEscape:
8GuiClose:
    ExitApp

Pic1L:
MsgBox, Left Click on Picture 1
return

Pic2L:
MsgBox, Left Click on Picture 2
return

Pic1M:
MsgBox, Middle Click on Picture 1
return

Pic2M:
MsgBox, Middle Click on Picture 2
return

Pic1R:
MsgBox, Right Click on Picture 1
return

Pic2R:
MsgBox, Right Click on Picture 2
return


Spark
Posts: 80
Joined: 04 Jan 2017, 02:22

Re: Click Action on GUI

24 May 2018, 23:17

OMG... Thx So much :clap:
AHKd00b wrote:You're welcome in advance :crazy:

Code: Select all

Z1 = C:\Program Files\AutoHotkey\AutoHotkey.exe
Z2 = C:\Program Files\AutoHotkey\AU3_Spy.exe
Gui, 8:Add, Picture, vPic1 gcase x5 y5 w50 h50, %Z1%
Gui, 8:Add, Picture, vPic2 gcase xp+75 y5 w50 h50 , %Z2%
Gui, 8:Show

OnMessage(0x0201, "WM_LBUTTONDOWN")
OnMessage(0x0207, "WM_MBUTTONDOWN")
OnMessage(0x0204, "WM_RBUTTONDOWN")

case:
	return

WM_LBUTTONDOWN() {
	if A_GuiControl = Pic1
		gosub Pic1L
	else if A_GuiControl = Pic2
		gosub Pic1L
}

WM_RBUTTONDOWN() {
	if A_GuiControl = Pic1
		gosub Pic1R
	else if A_GuiControl = Pic2
		gosub Pic1R
}

WM_MBUTTONDOWN() {
	if A_GuiControl = Pic1
		gosub Pic1M
	else if A_GuiControl = Pic2
		gosub Pic1M
}

8GuiEscape:
8GuiClose:
    ExitApp

Pic1L:
MsgBox, Left Click on Picture 1
return

Pic2L:
MsgBox, Left Click on Picture 2
return

Pic1M:
MsgBox, Middle Click on Picture 1
return

Pic2M:
MsgBox, Middle Click on Picture 2
return

Pic1R:
MsgBox, Right Click on Picture 1
return

Pic2R:
MsgBox, Right Click on Picture 2
return


gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: Click Action on GUI

24 May 2018, 23:27

You may use other window messages like WM_RBUTTONDOWN = 0x204 and WM_MBUTTONDOWN = 0x207 for right click and middle button click.

If you add handles to the Picture controls via the hwnd option, you can also differentiate between the pictures (and non-picture area) - see below:

Code: Select all

Z1 = C:\Program Files\AutoHotkey\AutoHotkey.exe
Z2 = C:\Program Files\AutoHotkey\AU3_Spy.exe
Gui, 8:Add, Picture, x5 y5 w50 h50 gPic1 hwndImg1, %Z1%
Gui, 8:Add, Picture, xp+75 y5 w50 h50 gPic2 hwndImg2, %Z2%
Gui, 8:Show
OnMessage(0x200, "HelpTip")
OnMessage(0x204, "WM_RBUTTONDOWN")		
OnMessage(0x207, "WM_MBUTTONDOWN")
return

8GuiEscape:
8GuiClose:
    ExitApp

Pic1:
MsgBox, Left Click on Picture 1
return
Pic2:
MsgBox, Left Click on Picture 2
return

HelpTip(wParam, lParam, Msg) {
	global Z1,Z2
MouseGetPos,,,, OutputVarControl
IfEqual, OutputVarControl, Static1
	HelpTip := Z1
else IfEqual, OutputVarControl, Static2
	HelpTip := Z2
ToolTip % HelpTip
}

WM_RBUTTONDOWN(wParam, lParam, msg, hwnd){
	global img1, img2
	if (hwnd = img1)
		MsgBox, Right Click on Picture 1
	else if (hwnd = img2)
		MsgBox, Right Click on Picture 2
	else 
		MsgBox, Right Click outside of pictures 
}

WM_MBUTTONDOWN(wParam, lParam, msg, hwnd){
	global img1, img2
	if (hwnd = img1)
		MsgBox, Middle Click on Picture 1
	else if (hwnd = img2)
		MsgBox, Middle Click on Picture 2
	else 
		MsgBox, Middle Click outside of pictures 
}
(If needed, you could even determine at which coordinates the pictures were clicked.)

Edit: Oh, too late, but a slightly different way - so it might be instructional nevertheless :)
Last edited by gregster on 24 May 2018, 23:44, edited 1 time in total.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Click Action on GUI

24 May 2018, 23:35

Here is another approach that will allow you to not have to check through a list of controls.
It just checks if you right clicked or mclicked a control and then sends a click to it.
If it has a label it will go to it, if not, nothing happens besides it getting clicked.

Code: Select all

#SingleInstance,Force


Gui,1:+AlwaysOnTop
Gui,1:Color,Black
Gui,1:Add,Button,x50 y10 w200 h30 gMy_Test_Button,Test Button
Gui,1:Add,Button,x50 y85 w200 h30 gMy_Test_Button2,Test Button 5437
Gui,1:Show,w300 h200,Some random gui title
return
GuiClose:
*^ESC::
   ExitApp
   
My_Test_Button:
   Gui,1:+OwnDialogs
   msgbox, you pressed the test button `ncontrol id:%control%
   return
   
My_Test_Button2:
   Gui,1:+OwnDialogs
   msgbox, you pressed the test button 5437 `ncontrol id:%control%
   return   
   
#IfWinActive, Some random gui title ;sets all the hotkeys within #ifwinactive and #if to only work if the right window is active
Rbutton:: 
MButton::  
Mousegetpos,,,,Control   
if(control)
  controlclick,% control
else
   TrayTip,,No Control ,1
return
#if
Spark
Posts: 80
Joined: 04 Jan 2017, 02:22

Re: Click Action on GUI

24 May 2018, 23:45

@Hellbent, @gregster, and @AHKd00b

thx so much,

1 more question, is there a simpler way for global variables (besides adding 1 by 1)?
because i have many pictures..
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Click Action on GUI

24 May 2018, 23:55

Spark wrote: is there a simpler way for global variables (besides adding 1 by 1)?
because i have many pictures..
I have a tool that I use almost daily to create lists, arrays, and objects.
With it you can just select the image and press ctrl+c to add it to an array, list or object and then paste it into your script.

Here is the script:

Code: Select all

;Old pastes ;PasteBin Save: https://pastebin.com/4vJ9MhYT ;Version 1.2
;Version 1.4 Paste: https://pastebin.com/nD3JQ0G1 ;Nov 26th, 2017
#SingleInstance,Force
CoordMode,Mouse,Screen
Global Key_Input,Auto_Key_Amount:=5,Ax:=600,Ay:=200
Gui,1:+AlwaysOnTop +LastFound
Gui,1:Color,Teal,Black
Gui,1:Font,cBlack s8 Bold Q5,Segoe UI
Null_Var:="",Control_Types:= ["Edit","Groupbox","ListBox","Text","Edit","CheckBox","CheckBox","Groupbox","CheckBox","Text","Edit","CheckBox","Button","GroupBox","Text","Edit","Text","Edit"],Control_Text := [Output_String,"Settings / ETC","Object||Object w/Strings|Array|Array w/Strings|Pipe List","Name:",Null_Var,"Double Space Delimiter","Auto Clip Add",Null_Var,"Auto Keys","Amount:",Auto_Key_Amount,"Turn On Transparency","Clipboard","Input","Keys:",Null_Var,"Value:",Null_Var]
For, k, v in ["cBlack x10 y10 w1180 r3 ReadOnly vOutput_Edit","x10 y+5 w800 h100 Section","cWhite xs+10 ys+25 w120 r4 AltSubmit vOutType gDisplay_Output","cLime x+10 ys+25 w30","cWhite x+10 yp-2 w100 r1 vName gDisplay_Output","xs+140 y+10 vALT_Delimiter gDisplay_Output","xs+140 y+10 vAuto_Clip_Add gAuto_Clip","xs+300 ys+10 w125 h80 Section","xs+10 ys+20 vAuto_Keys gDisplay_Output","cLime xs+10 y+15","cRed x+10 yp-2 w50 r1 vAuto_Key_Amount gDisplay_Output","x+30 ys+10 vTimer gTurn_On_Off_Timer","xs+390 ys+60 w100 r1 -Theme gClip_All","x10 y+15 w1180 h130 Section","cLime xs+10 ys+20 w35","cWhite x+10 ys+18 w1120 r2 vKey_Input gDisplay_Output","cLime xs+10 y+10 w35","cWhite x+10 yp-2 w1120 r4 vValue_Input gDisplay_Output"]
	Gui,1:Add,% Control_Types[A_Index],% v ,% Control_Text[A_Index]
Gui,1:Submit,NoHide
Gui,1:Show,w1200 h305, Auto Objects v1.4
return
Auto_Clip:
	Gui,1:Submit,Nohide
	return
Turn_On_Off_Timer:
	Timer:=!Timer
	if(Timer)
		SetTimer,I_Want_To_See,100
	else	{
		SetTimer,I_Want_To_See,-1
	}
	return
I_Want_To_See:
	mouseGetPos,x1,y1
	WinGetPos,x2,y2,w2,h2,Auto Objects v1.4
	if(x1>=x2&&x1<=x2+w2&&y1>=y2&&y1<=y2+h2)
		Winset,Transparent,255,Auto Objects v1.4
	else
		winset,Transparent,20,Auto Objects v1.4
	return
GuiClose:
	ExitApp
Display_Output:
	Gui,1:Submit,NoHide
	GuiControl,1:Enable,Key_Input
	(ALT_Delimiter)?(Delimit:="  "):(Delimit:=" ")
	Quote = `"
	temp_Key:="",temp_Key:=[],temp_Value:="",temp_Value:=[]
	(OutType=1)?(S1:=Name ":= {",S2:=":",S3:=",",S4:=":",S5:="}" Run_Output(S1,S2,S3,S4,S5,"","1","0","0"))
	:(OutType=2)?(S1:=Name ":= {",S2:=":",S3:=",",S4:=":",S5:="}" Run_Output(S1,S2,S3,S4,S5,Quote,"1","0","0"))
	:(OutType=3)?(S1:=Name ":= [",S2:=",",S3:="]",S4:="",S5:="" Run_Output(S1,S2,S3,S4,S5,"","0","1","0"))
	:(OutType=4)?(S1:=Name ":= [",S2:=",",S3:="]",S4:="",S5:="" Run_Output(S1,S2,S3,S4,S5,Quote,"0","1","0"))
	:(OutType=5)?(S1:=Name ":= " Quote,S2:="|",S3:=Quote,S4:="",S5:="" Run_Output(S1,S2,S3,S4,S5,Quote,"0","1","1"))
	return
Clip_All:
	sleep,20
	Clipboard:=Output_Edit
	return
Move_Tab:
	PostMessage,0xA1,2
	While(GetKeyState("LButton"))
		Sleep, 10
	WinGetPos,Ax,Ay,,,AUTO TAB v1.4
	return
2GuiContextMenu:
	Gui,2:Destroy
	Gui,1:Show
	return	
GuiContextMenu:
	Gui,1:Minimize
	Gui,2:Destroy
	Gui,2:+AlwaysOnTop -Caption +Border +Owner1
	Gui,2:Color,Gray
	Gui,2:Font,cWhite s7 Bold Q5,Segoe UI
	Gui,2:Add,Text,x0 y5 w50 h20 Center gMove_Tab,AUTO OBJ
	Gui,2:Show,x%Ax% y%Ay% w50 h20,AUTO TAB v1.4
	return
Run_Output(S1,S2,S3,S4,S5,EQ,FULL,DisableIt,Organ){
	global
	Output_Edit:=""
	if(DisableIt=1)
		GuiControl,1:Disable,Key_Input
	if(Full=1){
		if(Auto_Keys=0){
			Loop,Parse,Key_Input,% Delimit 
				temp_Key[A_Index]:=A_LoopField
		}else	{
			GuiControl,1:Disable,Key_Input
			Loop,% Auto_Key_Amount
				temp_Key[A_Index]:= A_Index
		}
	}
	Split_Array:=strsplit(Value_Input, Delimit)
	if(Organ=0){
		for,k,v in Split_Array
			temp_Value[k]:=EQ v EQ
	}
	else	{
		for,k,v in Split_Array
			temp_Value[k]:=v S2
	}
	Output_Edit.= S1
	(temp_Value.MaxIndex()>temp_Key.MaxIndex())?(Loop_Amount:=temp_Value.MaxIndex()):(Loop_Amount:=temp_Key.MaxIndex())
	Loop % Loop_Amount	{
		if(Full=1){
			if(A_Index!=temp_Value.MaxIndex())
				Output_Edit.=temp_Key[A_Index] S2 temp_Value[A_Index] S3 
			else
				Output_Edit.=temp_Key[A_Index] S4 temp_Value[A_Index] S5
		}else	{
			if(Organ=0){
				if(A_Index!=temp_Value.MaxIndex())
					Output_Edit.=temp_Value[A_Index] S2 
				else
					Output_Edit.= temp_Value[A_Index] S3
			}else	{
				if(A_Index!=temp_Value.MaxIndex())
					Output_Edit.=temp_Value[A_Index]
				else
					Output_Edit.= temp_Value[A_Index] S3
			}	
		}
	}
	GuiControl,1:,Output_Edit,% Output_Edit	
}
~^C::
	sleep,50
	if(Auto_Clip_Add=1&&ALT_Delimiter=1){
		Value_Input.= Clipboard "  "
		GuiControl,1:,Value_Input,% Value_Input
		gosub,Display_Output
	}
	else if(Auto_Clip_Add=1&&ALT_Delimiter=0){
		Value_Input.= Clipboard " "
		GuiControl,1:,Value_Input,% Value_Input
		gosub,Display_Output
	}
	return
Here is a short tut on how to run it.

https://www.youtube.com/watch?v=hy0Kh1fDuvY
Spark
Posts: 80
Joined: 04 Jan 2017, 02:22

Re: Click Action on GUI

25 May 2018, 00:53

@Hellbent

Thanks a million for your help :bravo:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 410 guests