Click on a certain area of a Window when mouse is over a certain area of the window

Get help with using AutoHotkey and its commands and hotkeys
dbazinga
Posts: 3
Joined: 12 Mar 2020, 09:36

Click on a certain area of a Window when mouse is over a certain area of the window

12 Mar 2020, 10:06

Hello,
I need some help. Unfortunately my knowledge in this are is very limited, so I really didnt know what to look for.
In the past I used AHK to click on a specific area of the window when the cursor was hovering over it. This is what I used

Code: Select all

if(WinActive("....") && WinActive("ahk_exe ....."))
{
WinGetPos X, Y, width, height, A
vX:=width*0.2545
vY:=height*0.9426
MouseClick, Left, vX, vY, 1, 0
;ControlClick, % "x" vX " y" vY,,, Left, 1, NA
;vY:=height*0.8995
;MouseClick, Left, vX, vY, 1, 0
;ControlClick, % "x" vX " y" vY,,, Left, 1, NA
}
else 
I created a drawing to illustrate :lol:
click.jpg
click.jpg (28.94 KiB) Viewed 403 times
Now what I need it to do is to split the window in 4 parts and treat each as if it is its own window.
Lets say the mouse is anywhere over the gray part and I left click, I want it to click on the marked spot of gray area. Same goes for the other parts.

Thanks guys :thumbup:

PS: I would also be willing to pay for it, if this is quite difficult to do.
User avatar
Hellbent
Posts: 1058
Joined: 23 Sep 2017, 13:34

Re: Click on a certain area of a Window when mouse is over a certain area of the window

12 Mar 2020, 15:01

Try this.

Code: Select all

#SingleInstance, Force
SetBatchLines, -1
CoordMode, Mouse, Client
Gui, 1:+AlwaysOnTop -DPIScale hwndGuiHwnd
Gui, 1:Color, 222222
Gui, 1:Font, cBlack s10 Bold
y := 10 , w := 80 , h := 80 , Index := 1 , colors := ["880016","7F7F7F","00A3E8","FEF200"] , cCount := [0,0,0,0] , positions := []
Loop, 2	{
	x := 10
	Loop, 2	{
		positions[Index] := {X:x,Y:y,W:w,H:h}
		Gui, 1:Add, Text, % "x" x " y" y " w" w " h" h " vTrigger" Index " gUpdate" 
		Gui, 1:Add, Progress, % "x" x " y" y " w" w " h" h " Background" colors[Index]
		Gui, 1:Add, Text, % "x" x " y" y " w" w " h" h " Backgroundtrans Center 0x200 vText" Index , % cCount[Index]
		Index++ , x += 100
	}
	y += 100
}
Gui,1:Show,w200 h200,Demo
SetTimer, WatchCursor, 50
return
GuiClose:
GuiContextMenu:
*Esc::
	ExitApp
WatchCursor:
	if(WinActive("ahk_id " GuiHwnd)){
		MouseGetPos,tx,ty
		Loop, 4	{
			if( tx >= Positions[A_Index].X && tx <= Positions[A_Index].X + Positions[A_Index].W && ty >= Positions[A_Index].Y && ty <= Positions[A_Index].Y + Positions[A_Index].H ){
				click,
				return
			}
		}
	}
	return
Update:
	Index := SubStr(A_GuiControl,8,1)
	GuiControl,1:,Text%Index%, % ++cCount[Index]
	return
Last edited by Hellbent on 12 Mar 2020, 15:16, edited 1 time in total.
User avatar
Hellbent
Posts: 1058
Joined: 23 Sep 2017, 13:34

Re: Click on a certain area of a Window when mouse is over a certain area of the window

12 Mar 2020, 15:14

With fixed click positions.

Code: Select all

#SingleInstance, Force
SetBatchLines, -1
CoordMode, Mouse, Client
Gui, 1:+AlwaysOnTop -DPIScale hwndGuiHwnd
Gui, 1:Color, 222222
Gui, 1:Font, cBlack s10 Bold
y := 10 , w := 80 , h := 80 , Index := 1 , colors := ["880016","7F7F7F","00A3E8","FEF200"] , cCount := [0,0,0,0] , positions := []
Loop, 2	{
	x := 10
	Loop, 2	{
		positions[Index] := {X:x,Y:y,W:w,H:h}
		Gui, 1:Add, Text, % "x" x " y" y " w" w " h" h " vTrigger" Index " gUpdate" 
		Gui, 1:Add, Progress, % "x" x " y" y " w" w " h" h " Background" colors[Index]
		Gui, 1:Add, Text, % "x" x " y" y " w" w " h" h " Backgroundtrans Center 0x200 vText" Index , % cCount[Index]
		Index++ , x += 300
	}
	y += 300
}
Gui,1:Show,w400 h400,Demo
SetTimer, WatchCursor, 200
return
GuiClose:
GuiContextMenu:
*Esc::
	ExitApp
WatchCursor:
	if(WinActive("ahk_id " GuiHwnd)){
		MouseGetPos,tx,ty
		Loop, 4	{
			if( tx >= Positions[A_Index].X && tx <= Positions[A_Index].X + Positions[A_Index].W && ty >= Positions[A_Index].Y && ty <= Positions[A_Index].Y + Positions[A_Index].H ){
				px := Positions[A_Index].X + 10 , py := Positions[A_Index].Y + 70
				click, %px%, %py%
				return
			}
		}
	}
	return
Update:
	Index := SubStr(A_GuiControl,8,1)
	GuiControl,1:,Text%Index%, % ++cCount[Index]
	return
dbazinga
Posts: 3
Joined: 12 Mar 2020, 09:36

Re: Click on a certain area of a Window when mouse is over a certain area of the window

12 Mar 2020, 16:12

Hey there. Thanks for your reply. I think I didnt explain it quite right ^^. I use the script for an App. I actually figured a little bit out on my own, but I have a problem when there are more than one click after the Hotkey gets triggered. It works perfectly for the Rbutton, but the Y Button, the cursor does what it is supposed to, but then jumps all over the window (I guess it executes all other commands and doesnt stop at the right time.
Here is the code I use

Code: Select all


 #SingleInstance force
#NoEnv
#Persistent

setTimer, activator, 50
return

activator:
MouseGetPos, , , id, control
wingetclass,class,ahk_id%id%
wingettitle,title,ahk_id%id%
if (class="GLFW30") & (instr(title, "BETA")>0)
{
Suspend, Off
WinActivate, ahk_id %id%
}
else
Suspend, On
return


RButton::
CoordMode, Mouse, Relative

if(WinActive("ahk_class GLFW30") && WinActive("ahk_exe beta.exe"))
{

MouseGetPos, x,y

if (x > 0 and x < 425  and y < 775 and y > 0)
MouseClick, Left, 87, 750, 1, 0

if (x > 425 and x < 845  and y < 775 and y > 0)
MouseClick, Left, 528, 750, 1, 0

if (x > 0 and x < 425  and y < 1520 and y > 775)
MouseClick, Left, 87, 1487, 1, 0

if (x > 425 and x < 845  and y < 1520 and y > 775)
MouseClick, Left, 528, 1487, 1, 0

}

return



y::
CoordMode, Mouse, Relative

if(WinActive("ahk_class GLFW30") && WinActive("ahk_exe beta.exe"))
{

MouseGetPos, x,y

if (x > 0 and x < 425  and y < 775 and y > 0)
MouseClick, Left, 356, 746, 1, 0
sleep 150
MouseClick, Left, 276, 608, 1, 0
sleep 150
MouseClick, Left, 356, 746, 1, 0


if (x > 425 and x < 845  and y < 775 and y > 0)
MouseClick, Left, 775, 750, 1, 0
sleep 150
MouseClick, Left, 700, 608, 1, 0
sleep 150
MouseClick, Left, 775, 750, 1, 0


if (x > 0 and x < 425  and y < 1520 and y > 775)
MouseClick, Left, 356, 1490, 1, 0
sleep 150
MouseClick, Left, 276, 1349, 1, 0
sleep 150
MouseClick, Left, 356, 1490, 1, 0

if (x > 425 and x < 845  and y < 1520 and y > 775)
MouseClick, Left, 775, 1490, 1, 0
sleep 150
MouseClick, Left, 700, 1349, 1, 0
sleep 150
MouseClick, Left, 775, 1490, 1, 0

}

return
Why doesnt it work with the y button?
Thx
User avatar
Hellbent
Posts: 1058
Joined: 23 Sep 2017, 13:34

Re: Click on a certain area of a Window when mouse is over a certain area of the window

12 Mar 2020, 16:23

a if() with more than one line needs { }

Code: Select all


if(something)
	msgbox, this works fine

if(something){
	blah blah
	blah blah
	msgbox, this needs to be enclosed
}


Return to “Ask For Help”

Who is online

Users browsing this forum: boiler, mikeyww, roonyroox, RubbeH, songdg, vomitsurfer and 53 guests