Problem by putting codes together. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zortanmax
Posts: 32
Joined: 15 Jan 2019, 08:25

Problem by putting codes together.

17 Feb 2019, 14:54

Hi everyone
I put the code together so that I can get the desired result. The problem is that each of the parts run without problems, the first and the second parts run without problems, but when I add the third part of the code, only the third part runs.

Code: Select all

; Part 1
#Persistent
SetTimer, Alert1, 500
return

Alert1:
IfWinNotExist, Start menu ahk_class DV2ControlHost 
    return

SetTimer, Alert1, Off
Sleep, 1000

; Part 2
#persistent
SetTimer, MouseCheck, 100 
MouseCheck:
MouseGetPos, MouseX, MouseY

If MouseX between 270 and 335
If MouseY between 553 and 570

; Part 3
Lbutton::
    while (GetKeyState("Lbutton", "P")) {
        MsgBox You Pressed Left Button!
    }
return



;I am a beginner in
Autokey?
{
HotKey??
AutoHotKey
}
return
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Problem by putting codes together.

17 Feb 2019, 15:23

Hi zortanmax

Is the code in your post all part of the same script?
Written the same way as you posted it?
User avatar
SL5
Posts: 879
Joined: 12 May 2015, 02:10
Contact:

Re: Problem by putting codes together.

17 Feb 2019, 16:31

zortanmax wrote:
17 Feb 2019, 14:54
Hi everyone
I put the code together so that I can get the desired result. The problem is that each of the parts run without problems, the first and the second parts run without problems, but when I add the third part of the code, only the third part runs.
...
thats often if you use labels.
typically at the end of a script.

i you include diffecte script together its best not to use labels.

you also could use timer with functions:

https://autohotkey.com/docs/objects/Functor.htm

i dont know if that helps. BTW that was one of my problems today
zortanmax
Posts: 32
Joined: 15 Jan 2019, 08:25

Re: Problem by putting codes together.

17 Feb 2019, 16:42

Hellbent wrote:
17 Feb 2019, 15:23
Hi zortanmax

Is the code in your post all part of the same script?
Written the same way as you posted it?

Yes, I just divided it into three parts. I'm beginner in coding, I just put the sections together.
;I am a beginner in
Autokey?
{
HotKey??
AutoHotKey
}
return
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Problem by putting codes together.  Topic is solved

17 Feb 2019, 17:19

Can you describe what you want your script to do.
Perhaps walk through the logic in point form.

ATM, this is my best guess at what you are trying to do.

Code: Select all

#SingleInstance,Force

IfWinNotExist, Start menu ahk_class DV2ControlHost   ; if the window doesn't exist, do nothing, exit the script
	ExitApp

SetTimer,MouseCheck,100 ; set a timer to check mouse position within the "Start menu ahk_class DV2ControlHost" window.

return

MouseCheck:
	MouseGetPos, MouseX, MouseY
	if( MouseX > 270 && MouseX < 335 && MouseY > 553 && MouseY < 570 && WinActive("Start menu ahk_class DV2ControlHost")){ ;if the mouse is between x and y and the window is active, turn on the hotkey.
		
		Activate_Hotkey:=1
		
	}else	{ ; else , deactivate the hotkey
		
		Activate_Hotkey:=0
		
	}
	return

#If (Activate_Hotkey=1)

Lbutton::                                      ; if the hotkey is activated, allow it's use.
	while (GetKeyState("Lbutton", "P")) {
		MsgBox You Pressed Left Button!
	}
	return
	
#If
zortanmax
Posts: 32
Joined: 15 Jan 2019, 08:25

Re: Problem by putting codes together.

18 Feb 2019, 00:51

I would like to see a message on the screen when click on the shutdown button.
thanks a lot Helbent for the script and description; My problem has been resolved.
;I am a beginner in
Autokey?
{
HotKey??
AutoHotKey
}
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 300 guests