give a image a click function

Ask gaming related questions (AHK v1.1 and older)
DRLantern
Posts: 45
Joined: 05 May 2023, 20:21

Re: give a image a click function

Post by DRLantern » 04 Jun 2023, 22:12

@boiler hey so there is a bad thing that has happened witht he buttons, well what happened is i put in the code for the 2 gui buttons i ahve, but for somer eason when i rpess joy1 with the image anwyhere on the gui it does the following instead of just pressing on the button watch, https://drive.google.com/file/d/1YflEmMU8neP-bndKtuuoH-XOOP4Th-rQ/view?usp=drive_link


also here is the code

Code: Select all

JoyNomX := GetKeyState("JoyX")
JoyNomY := GetKeyState("JoyY")

Gui, add, Button, x50 y150 w500 h500, &OK
Gui, add, Button, x0 y0 w200 h200, &Go

Gui, Add, Picture, x20 y40 w20 h-1 vMousePic, %IMAGEPATH1%
Gui, Show, w800 h600, testing lol
SetTimer, MoveMouse, 20
return

MoveMouse:
	GuiControlGet, Pic, Pos, MousePic
	GuiControl, Move, MousePic, % "x" (PicX + (GetKeyState("JoyX") - JoyNomX) / 1) " y"	(PicY + (GetKeyState("JoyY") - JoyNomY) / 1)
	Sleep, 20
return


Joy1::
	GuiControl,, MousePic, %IMAGEPATH2%
	KeyWait, Joy1
	GuiControl,, MousePic, %IMAGEPATH1%
if (PicX > 50) && (PicY > 150) 
		Gosub, ButtonOK
else
if (PicX > 0) && (PicY > 0) 
		Gosub, ButtonGo
return

ButtonOK:
msgbox, DONE1
Return

ButtonGo:
msgbox, DONE2
Return

DRLantern
Posts: 45
Joined: 05 May 2023, 20:21

Re: give a image a click function

Post by DRLantern » 04 Jun 2023, 22:18

im trying tof igure this out
Last edited by DRLantern on 05 Jun 2023, 15:01, edited 1 time in total.

User avatar
boiler
Posts: 16957
Joined: 21 Dec 2014, 02:44

Re: give a image a click function

Post by boiler » 04 Jun 2023, 22:20

I don’t know why you posted the exact same post three times in a row (I deleted two of them), and I don’t know why you changed the if conditions to look nothing like my examples and to not make logical sense and then ask why it doesn’t work.

DRLantern
Posts: 45
Joined: 05 May 2023, 20:21

Re: give a image a click function

Post by DRLantern » 05 Jun 2023, 13:29

boiler wrote: I don’t know why you posted the exact same post three times in a row (I deleted two of them), and I don’t know why you changed the if conditions to look nothing like my examples and to not make logical sense and then ask why it doesn’t work.
that's because I'm first trying to find out what i typed or tried typing, also i tried to figure out if it typed in the main thread or just typing your name sorry, anyway, is there a type of thing where if PICX or PICY can be any Coordinate then it wont do the action except for just clicking on the GuI button with joy1 with image

DRLantern
Posts: 45
Joined: 05 May 2023, 20:21

Re: give a image a click function

Post by DRLantern » 05 Jun 2023, 14:57

so yea is there a fix for that

User avatar
boiler
Posts: 16957
Joined: 21 Dec 2014, 02:44

Re: give a image a click function

Post by boiler » 05 Jun 2023, 19:05

DRLantern wrote: is there a type of thing where if PICX or PICY can be any Coordinate then it wont do the action except for just clicking on the GuI button with joy1 with image
I don’t know what you’re asking. And again, the image doesn’t click anything. What are you trying to say? If PicX and PicY can be any coordinate, then it doesn’t have anything to do with where the image is, right? So are you really saying that if the user presses Joy1, then you want to execute the subroutine associated with the button? So what does the position have to do with anything? Are you just ignoring it now?

I’m reaching the end of my help here. Try to clearly and logically spell out what you want to happen when certain actions are taken by the user.

DRLantern
Posts: 45
Joined: 05 May 2023, 20:21

Re: give a image a click function

Post by DRLantern » 05 Jun 2023, 19:22

what the position has to do with the Gui button is when i click anywhere in the Gui button except for when i press a blank spot on the Gui window without pressing on the Gui button with joy1 it still does what its supposed to do with the Gui button except on a the Gui itself, basically when I press on the Gui with joy1, its pressing on the Gui where there is no widget being on the Gui, make sense, i want a script to where when i press on the 2 Gui buttons indivisibly it only makes sure it presses on the Gui button and not the where there is no widget on the Gui, also known as in the Gui itself to where when I press where I'm not pressing the
gui button but still pressing on where there is no widget I'm pressing, i want that to do nothing but for when I'm pressing on the 2 buttons individually, do u get me now, and one last thing, I want a border to where when I'm moving the image inside the Gui the image wouldn't go anyway where I can find the image where I'm moving the image, for some reason the image move to out of nowhere where i cant find it, so i want a border to where the image can only be where the same weight and height the Gui is and not disappear

User avatar
boiler
Posts: 16957
Joined: 21 Dec 2014, 02:44

Re: give a image a click function

Post by boiler » 05 Jun 2023, 20:31

DRLantern wrote: what the position has to do with the Gui button is when i click anywhere in the Gui button except for when i press a blank spot on the Gui window without pressing on the Gui button with joy1 it still does what its supposed to do with the Gui button except on a the Gui itself, basically when I press on the Gui with joy1, its pressing on the Gui where there is no widget being on the Gui, make sense, i want a script to where when i press on the 2 Gui buttons indivisibly it only makes sure it presses on the Gui button and not the where there is no widget on the Gui, also known as in the Gui itself to where when I press where I'm not pressing the
gui button but still pressing on where there is no widget I'm pressing, i want that to do nothing but for when I'm pressing on the 2 buttons individually
It sounds like you are saying something like this where if it’s not over either button, then do the third thing:

Code: Select all

Joy1::
	GuiControl,, MousePic, %IMAGEPATH2%
	KeyWait, Joy1
	GuiControl,, MousePic, %IMAGEPATH1%
	if (PicX > 200) && (PicX < 250) && (PicY > 100) && (PicY < 150)
		Gosub, ButtonOK
	else if (PicX > 375) && (PicX < 400) && (PicY > 425) && (PicY < 550)
		Gosub, ButtonGo
	else
		Gosub, ButtonAnywhere
return

DRLantern wrote: I want a border to where when I'm moving the image inside the Gui the image wouldn't go anyway where I can find the image where I'm moving the image, for some reason the image move to out of nowhere where i cant find it, so i want a border to where the image can only be where the same weight and height the Gui is and not disappear
You check PicX and PicY reset them when they go beyond a certain point:

Code: Select all

MoveMouse:
	GuiControlGet, Pic, Pos, MousePic
	if (PixX < 50)
		PicX := 50
	if (PixX > 350)
		PicX := 350
	if (PixY < 50)
		PicY := 50
	if (PixY > 250)
		PicY := 250
	GuiControl, Move, MousePic, % "x" (PicX + (GetKeyState("JoyX") - JoyNomX) / 1) " y"	(PicY + (GetKeyState("JoyY") - JoyNomY) / 1)
	Sleep, 20
return

DRLantern
Posts: 45
Joined: 05 May 2023, 20:21

Re: give a image a click function

Post by DRLantern » 11 Jun 2023, 12:13

boiler wrote:
04 Jun 2023, 17:14
This seems like something you could have at least tried to modify yourself.

Code: Select all

Joy1::
	GuiControl,, MousePic, %IMAGEPATH2%
	KeyWait, Joy1
	GuiControl,, MousePic, %IMAGEPATH1%
	if (PicX > 200) && (PicX < 250) && (PicY > 100) && (PicY < 150)
		Gosub, ButtonOK
	if (PicX > 375) && (PicX < 400) && (PicY > 425) && (PicY < 550)
		Gosub, ButtonGo
return

hey boiler, so i was tryignt of ind the cordinates of eatch button when hover over with image, i was wondering how i can do that, and im gonna be well as specfific as possible, lets say the gui button i press with joy1 isnt working because it added only "(PicX > ) && (PicY < )" because when i was pressing on the gui button with joy1 when image is hoveing over it it works but it only goes to the cordinate not the button itself, so that basically mean when i press the same cordinate where the position of the cordinate near the gui button is it kinda does the following on the gui instead of the button, i also tried to do the third following but it first following always come first for some reason, how can i fix this, and thx for me needing to eplain things im trying my best, that will be all

User avatar
boiler
Posts: 16957
Joined: 21 Dec 2014, 02:44

Re: give a image a click function

Post by boiler » 11 Jun 2023, 13:31

Well, first of all, "(PicX > ) && (PicY < )" would not define an area fully since you are only defining the lower bound of X and the upper bound of Y. Why are you doing that? No reason to go further until you’re defining the conditions correctly.

DRLantern
Posts: 45
Joined: 05 May 2023, 20:21

Re: give a image a click function

Post by DRLantern » 11 Jun 2023, 13:51

well here is my code, sorry if i dont knwo the upper bounds and lower bounds, i just hope someone would explain it to me so i can do yt myself

Code: Select all

#SingleInstance Forc
#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines -1

JoyNomX := GetKeyState("JoyX")
JoyNomY := GetKeyState("JoyY")



Gui Add, Button, x8 y8 w152 h82, &Button1
Gui Add, Button, x8 y128 w152 h82, &Button2
Gui Add, Button, x8 y248 w152 h82, &Button3
Gui Add, Button, x8 y376 w152 h82, &Button4
Gui Add, Button, x8 y504 w152 h82, &Button5
Gui Add, Button, x200 y8 w152 h82, &Button6
Gui Add, Button, x200 y120 w152 h82, &Button7
Gui Add, Button, x200 y240 w152 h82, &Button8
Gui Add, Button, x208 y376 w152 h82, &Button9
Gui Add, Button, x208 y504 w152 h82, &Button10
Gui Add, Button, x392 y8 w152 h82, &Button11
Gui Add, Button, x392 y120 w152 h82, &Button12
Gui Add, Button, x392 y232 w152 h82, &Button13
Gui Add, Button, x400 y376 w152 h82, &Button14
Gui Add, Button, x400 y496 w152 h82, &Button15
Gui Add, Button, x568 y8 w152 h82, &Button16
Gui, Add, Picture, x20 y20 w20 h20 vMousePic, 
Gui Show, w746 h682, Button Test
SetTimer, MoveMouse, 20
Return

MoveMouse:
	GuiControlGet, Pic, Pos, MousePic
	GuiControl, Move, MousePic, % "x" (PicX + (GetKeyState("JoyX") - JoyNomX) / 1)  "y" (PicY + (GetKeyState("JoyY") - JoyNomY) / 1)
	Sleep, 15
return

Joy1::
	if (PicX > ) && (PicX < ) && (PicY > ) && (PicY < )
		Gosub, Button1
	 if (PicX > ) && (PicX < ) && (PicY > ) && (PicY < )
		Gosub, Button2
 if (PicX > ) && (PicX < ) && (PicY > ) && (PicY < )
		Gosub, Button3
 if (PicX > ) && (PicX < ) && (PicY > ) && (PicY < )
		Gosub, Button4
if (PicX > ) && (PicX < ) && (PicY > ) && (PicY < )
		Gosub, Button5
if (PicX > ) && (PicX < ) && (PicY > ) && (PicY < )
		Gosub, Button6
 if (PicX > ) && (PicX < ) && (PicY > ) && (PicY < )
		Gosub, Button7
 if (PicX > ) && (PicX < ) && (PicY > ) && (PicY < )
		Gosub, Button8
 if (PicX > ) && (PicX < ) && (PicY > ) && (PicY < )
		Gosub, Button9
 if (PicX > ) && (PicX < ) && (PicY > ) && (PicY < )
		Gosub, Button10
 if (PicX > ) && (PicX < ) && (PicY > ) && (PicY < )
		Gosub, Button11
 if (PicX > ) && (PicX < ) && (PicY > ) && (PicY < )
		Gosub, Button12
 if (PicX > ) && (PicX < ) && (PicY > ) && (PicY < )
		Gosub, Button13
 if (PicX > ) && (PicX < ) && (PicY > ) && (PicY < )
		Gosub, Button14
 if (PicX > ) && (PicX < ) && (PicY > ) && (PicY < )
		Gosub, Button15
 if (PicX > ) && (PicX < ) && (PicY > ) && (PicY < )
		Gosub, Button16
	return


Button1:
msgbox, new1
return


Button2:
msgbox, new2
return

Button3:
msgbox, new3
return


Button4:
msgbox, new4
return


Button5:
msgbox, new5
return



Button6:
msgbox, new6
return



Button7:
msgbox new7
return


Button8:
msgbox, new8
return


Button9:
msgbox, new9
return

Button10:
msgbox, new10
return

Button11:
msgbox, new11
return

Button12:
msgbox, new12
return


Button13:
msgbox, new13
return

Button14:
msgbox, new14
return

Button15:
msgbox, new15
return


Button16:
msgbox, new16
return
Last edited by DRLantern on 11 Jun 2023, 13:58, edited 1 time in total.

User avatar
boiler
Posts: 16957
Joined: 21 Dec 2014, 02:44

Re: give a image a click function

Post by boiler » 11 Jun 2023, 13:58

Then you need to figure it out. It the range of x values and the range of y values that define the area of the button within the window.

Post Reply

Return to “Gaming Help (v1)”