give a image a click function

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

give a image a click function

Post by DRLantern » 28 May 2023, 17:27

hello, i was just wondering if there is any way to make a mouse cursor image have a click function in a Gui, for example, lets say the image will change inside of the Gui when u press any button, like when u press button a the image will not stay open for very long or is open for very long when u press a button on change, then when u hold down on button a it will tell the image to click on a certain button on Gui if thats possible on ahk please tell me and i will try to find out how to do it myself

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

Re: give a image a click function

Post by boiler » 28 May 2023, 22:01

You need to be much clearer about the terms you use and what you are describing as things you want the script to do and what are things you may be saying the application may do as a result of being acted upon. For example an image cannot click on a button, as you put it. Images don’t click. Images are displayed. How do you tell an image to click a button? It’s not possible to tell you if what you described is possible because it’s frankly not coherent.

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

Re: give a image a click function

Post by DRLantern » 29 May 2023, 00:11

basically here is my script

Code: Select all

JoyNomX := GetKeyState("JoyX") - 1
JoyNomY := GetKeyState("JoyY") - 1
JoyNomX := GetKeyState("JoyX") - 0
JoyNomY := GetKeyState("JoyY") - 0

Gui, +HwndGuiHwnd
Gui, Color, 5186D2
Gui, add, Button, x200 y200 w200 h200, &OK
Gui, Add, Picture, x300 y150 w200 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::
Critical
GuiControl,, MousePic, %IMAGEPATH2%
SetTimer, Check, 100
return

Check:
#If !GetKeyState("Joy1","p")
GuiControl,, MousePic, %IMAGEPATH1%
SetTimer, Check, Off
    return





as u can see when i press joy1 the button changes the image when i press 1 time or many, somehow i want joy1 to make it press on a button and then the button action will do what its suppost to do somehow it cant work fro some reason

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

Re: give a image a click function

Post by boiler » 29 May 2023, 02:20

One problem is that #If is a directive that only applies to hotkeys. It has no effect on your code. If you change it to a regular if statement, it would apply only to the line below it. If you want it to apply to both lines below it, you need to group them into a block using { }.

But there’s a much better way to wait for the Joy1 key to be released than to constantly check its star:

Code: Select all

Joy1::
Critical
GuiControl,, MousePic, %IMAGEPATH2%
KeyWait, Joy1
GuiControl,, MousePic, %IMAGEPATH1%
    return

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

Re: give a image a click function

Post by DRLantern » 29 May 2023, 03:30

thx man, but now i want to remap joy1 with a left mouseclick to make joy1 make it think its clicking on the gui button, is there any way to do that here is a video if u want to see it https://drive.google.com/file/d/1_2AcSbmBi44XCp24dqlazSDu04Koeh3m/view?usp=drive_link and that will be all

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

Re: give a image a click function

Post by boiler » 29 May 2023, 05:47

It says I don’t have access to that video.

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

Re: give a image a click function

Post by DRLantern » 29 May 2023, 12:17

ok now u have acccess to it, sorry i had to change it to veryone so yea

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

Re: give a image a click function

Post by boiler » 29 May 2023, 12:43

I would check the position of the picture control when it the Joy1 button is pressed and compare it to the location of the button, and if it's within the range of that button, then you execute the code related to that button press.

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

Re: give a image a click function

Post by DRLantern » 29 May 2023, 13:02

can u show me a code, ik i suck at this

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

Re: give a image a click function

Post by boiler » 29 May 2023, 13:48

Code: Select all

if (PicX > 200) && (PicX < 250) && (PicY > 100) && (PicY < 150)
	Gosub, ButtonOK

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

Re: give a image a click function

Post by DRLantern » 03 Jun 2023, 12:01

ok im here, can u explain to me what the this code does because i cant seem to get it to work

Code: Select all

if (PicX > 200) && (PicX < 250) && (PicY > 100) && (PicY < 150)
	Gosub, ButtonOK

User avatar
V0RT3X
Posts: 233
Joined: 20 May 2023, 21:59
Contact:

Re: give a image a click function

Post by V0RT3X » 03 Jun 2023, 13:38

I'll take a stab at this one and boiler can correct me if I'm wrong.

if (PicX > 200) && (PicX < 250) && (PicY > 100) && (PicY < 150)
Gosub, ButtonOK

As I'm understanding it, this breaks down like so...

it says that IF PicX is between 200 and 250, AND PicY is between 100 and 150, then it will process the GoSub command sending you to sub'd command you create named ButtonOK: that would be down towards the end of your script. That command would contain your code to run if conditions are met. Something like...

ButtonOK:
Your Code
Followed by a Return, to send you back to immediately after the GoSub command that sent you to the ButtonOK: command.

https://www.autohotkey.com/docs/v1/lib/Gosub.htm

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

Re: give a image a click function

Post by DRLantern » 03 Jun 2023, 14:44

what im really trying to do with gosub and picx and picy is trying to set the position of where joy1 is pressing the button with the image, and then it will say what type of image clicked the button, how do i do that and is it possible witht he code boiler showed me? ebcause it never worked, like where do i put the joy1 button to where it can make the image press the button with joy1, and if there is a way can u show me a code

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

Re: give a image a click function

Post by boiler » 03 Jun 2023, 14:55

@V0RT3X - That is exactly right.

@DRLantern - What you don't seem to be understanding is that that's how you do the equivalent of clicking the button. You Gosub to the subroutine that is defined fo rthe button click. You already have Joy1 where it's supposed to be: as a hotkey. And then you check the location of the image using the "if" statement to see if it's in the range of the button. And if you have more than one image, you check which one is in range.

So basically, something like this:

Code: Select all

Joy1::
	GuiControl,, MousePic, %IMAGEPATH2%
	KeyWait, Joy1
	GuiControl,, MousePic, %IMAGEPATH1%
	if (PicX > 200) && (PicX < 250) && (PicY > 100) && (PicY < 150)
		Gosub, ButtonOK
return
So when you press the Joy1 button, it does the little animation of the switch between images, then it executes the ButtonOK routine (the one that would execute if you clicked the OK button with your mouse) if the image is within the hot zone defined by that rectangle of coordinates.

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

Re: give a image a click function

Post by DRLantern » 03 Jun 2023, 18:43

ok i got it to work, how to do mutlipple label's with picx and picy and mutliple joy1's

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

Re: give a image a click function

Post by boiler » 04 Jun 2023, 06:36

I don’t know what you mean. You’re going to have to explain what you are trying to do clearly. Multiple labels for what? Are you going to have multiple buttons that could be clicked? How can you have multiple Joy1s? What do you really mean by that?

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

Re: give a image a click function

Post by DRLantern » 04 Jun 2023, 11:11

can u make this code to where u can have multiple gosub's, range cordinates, and more joy1's for this, im need to mak ethe image press one or more then two buttons indivisualy, is that possible




Code: Select all

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

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

Re: give a image a click function

Post by boiler » 04 Jun 2023, 12:32

I still don’t know what you mean by “more joy1’s.” There is only one Joy1 button. Are trying to say you want the Joy1 button to have the script do different things depending on the location of the image when Joy1 is pressed? Like which button the image is over when Joy1 is pressed?

Again, you need to be able to express what you expect your script to do in a clear and logical way if you want to have someone (even yourself) translate it into code. You use the expression that you want to make the image press buttons. Images don’t press buttons. They don’t do anything. They are displayed. If what you mean is you want the script to execute the subroutine associated with different buttons depending on the location of the image when the Joy1 button is pressed, then that’s how you need to describe it. Or else we’re just guessing at what you want.

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

Re: give a image a click function

Post by DRLantern » 04 Jun 2023, 14:24

"If what you mean is you want the script to execute the subroutine associated with different buttons depending on the location of the image when the Joy1 button is presse" yes thats what i mean, more gui buttons where the image is where the ocation of where joy1 is pressing here is a video of what i mean


https://drive.google.com/file/d/18c68bk1TltA8BKbmXbVcelyJxoONK24p/view?usp=drive_link

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

Re: give a image a click function

Post by boiler » 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

Post Reply

Return to “Gaming Help (v1)”