How to use ahk_pid with ControlSend/-Click

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
nabil_mumtaz
Posts: 8
Joined: 22 Jul 2021, 00:33

How to use ahk_pid with ControlSend/-Click

27 Jul 2021, 08:19

Code: Select all

{
ControlClick,x%x1% y%y1% ,Ahk_Pid %Window%A_Index%,,,, NA x%x1% y%y1%
sleep,80
{
ControlClick,x%x2% y%y2% ,Ahk_Pid %Window%A_Index%,,,, NA x%x2% y%y2%
sleep,80


loop,%HItung%
{
ControlSend,,{Space Down},Ahk_Pid %Window%A_Index%
sleep,500
}
ControlSend,,{space Up},Ahk_Pid %WIndow%A_Index%
sleep,175
}	
}
}

return
I don't know how to type all windows variables after ahk_pid
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: How to use ahk_pid with ControlSend/-Click

27 Jul 2021, 08:49

Possibly:

Code: Select all

ControlSend,, {Space down}, % "ahk_pid " Window%A_Index%
It works only inside a loop, because that is where A_Index has a value.

Demonstration:

Code: Select all

Window1 := 0xA, Window2 := 0xB
Loop, 2
 Send % Window%A_Index% "`n"
nabil_mumtaz
Posts: 8
Joined: 22 Jul 2021, 00:33

Re: How to use ahk_pid with ControlSend/-Click

27 Jul 2021, 09:31

Now Variable Hitung to suppress how much pressing space, not working properly
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: How to use ahk_pid with ControlSend/-Click

27 Jul 2021, 09:54

Feel free to post your revision, preferably including other key parts of the script.
nabil_mumtaz
Posts: 8
Joined: 22 Jul 2021, 00:33

Re: How to use ahk_pid with ControlSend/-Click

27 Jul 2021, 10:27

Code: Select all

#SingleINstance,On
DetectHIddenWindows,On
Gui,+AlwaysONTop

Gui,add,Button,x10 y10 w110 h25 gWindow_1,Window 1
Gui,add,Edit,x+10 w90 gUPdate vWindow1,

Gui,add,Button,x10 y+10 w110 h25 gWindow_2,Window 2
Gui,add,Edit,x+10 w90 gUPdate vWindow2,

Gui,add,Button,x10 y+10 w110 h25 gWindow_3,Window 3
Gui,add,Edit,x+10 w90 gUPdate vWindow3,

Gui,Add,Button,x10 y+10 gTarget1 ,Position 1
Gui,ADd,Edit,x+10 w130 vTArget1 gUpdate,

Gui,Add,Button,x10 y+10 gTarget2 ,Position 2
Gui,ADd,Edit,x+10 w130 vTArget2 gUpdate,

Gui,add,TExt,x10 y+10 ,Block Hit
Gui,add,Edit,x+10 w60 gUpdate,
Gui,add,updown,gUpdate vHitung,4

Gui,add,Button,x10 y+10 w100 h30 gStart vStart,Start
Gui,add,Button,x+10 w100 h30 gStop vStop,Stop


gui,Show,x0 y0,Try
return

Start:
Mulai := 1
GuiControl,Disable,Start
GuiControl,Enable,Stop

While (Mulai == 1)
{
ControlClick,x%x1% y%y1% , % "ahk_pid " Window%A_Index%,,,, NA x%x1% y%y1%
sleep,80
ControlClick,x%x2% y%y2% , % "ahk_pid " Window%A_Index%,,,, NA x%x2% y%y2%
sleep,80

loop,%Hitung%
{
ControlSend,, {Space down}, % "ahk_pid " Window%A_Index%
sleep,500
}
ControlSend,, {Space up}, % "ahk_pid " Window%A_Index%
sleep,175
}	

return

Stop:
Mulai := 0
GuiControl,Disable,Stop
GuiControl,Enable,Start
return

Target1:
Set_POsition(x1,y1)
GuiControl,,Target1,%x1% %y1%
return

Target2:
Set_POsition(x2,y2)
GuiControl,,Target2,%x2% %y2%
return

Set_Position(Byref X,Byref Y)
{
	i := 0
	k := 0
	loop {
		klik := GetKeyState("Lbutton")
		tooltip,Klik untuk set posisi
		if (Klik == False && k == 0)
		k := 1
		else if (klik == True && k == 1)
		{
		MouseGetPOs,x,y,
		tooltip,
		break
		{
}
}
}
Return TArget_Window
}

Select_Window:
Target_Window:=Set(Window)
Guicontrol,,Window,% Target_Window
Gui,Submit,Nohide
return

Window_1:
Target_Window:=Set(Window)
Guicontrol,,Window1,% Target_Window
Gui,Submit,Nohide
return

Window_2:
Target_Window:=Set(Window)
Guicontrol,,Window2,% Target_Window
Gui,Submit,Nohide
return

Window_3:
Target_Window:=Set(Window)
Guicontrol,,Window3,% Target_Window
Gui,Submit,Nohide
return

Set(Window)
{
	i := 0
	k := 0
	loop {
		klik := GetKeyState("Lbutton")
		tooltip,Klik 2 kali pada windows
		if (Klik == False && k == 0)
		k := 1
		else if (klik == True && k == 1)
		{
		i++ ,K:=0
		if (i>=2)
		{
		Winget,Target_Window,PID,A
		tooltip,
		break
}
}
}
Return TArget_Window
}

UPdate:
Gui,Submit,NOhide
return

GuiClose:
ExitAPp
return
this is an overview of the whole script
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: How to use ahk_pid with ControlSend/-Click

27 Jul 2021, 11:26

I see no explanation of the observed problem or the desired effect. I suggest going through the script line by line, following the flow. I see no definition of x1, y1, etc. To debug, you can add lines that display the results of your conditional statements and function calls.
nabil_mumtaz
Posts: 8
Joined: 22 Jul 2021, 00:33

Re: How to use ahk_pid with ControlSend/-Click

28 Jul 2021, 01:35

Code: Select all

{
loop,3
ControlClick,x%x1% y%y1% , % "ahk_pid " Window%A_Index%,,,, NA x%x1% y%y1%
sleep,80
{
loop,3
ControlClick,x%x2% y%y2% , % "ahk_pid " Window%A_Index%,,,, NA x%x2% y%y2%
sleep,80

}
SetKeyDelay,, 300
loop,3
ControlSend,, {Space %Hitung%}, % "ahk_pid " Window%A_Index%
}
works pretty well after scripting like this, but the problem now is that there's a long enough delay between Controlclick and Controlsend, whereas I added setkeydelay for controlsend.
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: How to use ahk_pid with ControlSend/-Click

29 Jul 2021, 07:54

You can always add a new sleep command if needed.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: NinjoOnline and 295 guests