Why is the first button firing automatically Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Why is the first button firing automatically

19 May 2017, 09:36

Hi,

I have the following code, and for some reason when I start the script, the code under the first button automatically
gets loaded. I can't figure out why though.

What am I missing ?

Code: Select all

#NoEnv
#Warn
#SingleInstance Force

DetectHiddenWindows, On
SetTitleMatchMode, 2

PathToScript1 = SRT\Afmelden\SRT Cloud afmelden.ahk
PathToScript2 = TSI\Afmelden\TSI Cloud afmelden.ahk
PathToScript3 = SRT\Afmelden\srt picklists v2.1.ahk
PathToScript4 = TSI\Afmelden\tsi picklists v2.ahk
PathToScript6b = SRT\\hotkeys.ahk v1.0.ahk
PathToScript7 = "\\WINSCHOTEN\Verkooporder\Salesorder.exe"
PathToScript8 = "\\WINSCHOTEN\Verkooporder\order importeren CLOUDVERSIE.ahk"

/*
y=top
x=left
*/

Gui,+AlwaysOnTop +LastFound +HwndGuiHwnd -Caption
Gui, Add, Button,   x10   y10  w100  h20 gScript1         , SRT afmelden
Gui, Add, Button,   x115  y10  w100  h20 gScript2         , TSI afmelden
Gui, Add, Button,   x10   y30  w100  h20 gScript3         , SRT automatisch
Gui, Add, Button,   x115  y30  w100  h20 gScript4         , TSI automatisch
Gui, Add, Button,   x10   y50  w100  h20 gScript5         , Reload SRT
Gui, Add, Button,   x115  y50  w100  h20 gScript6         , Reload TSI
Gui, Add, Button,   x10   y70  w100  h20 gScript6b        , Sneltoetsen
Gui, Add, Button,   x10   y90  w100  h20 gScript7         , Orderformulier
Gui, Add, Button,   x10   y110 w100  h20 gScript8         , Order importeren
Gui, Add, Button,   x115  y110 w100  h20 gScript9         , Reload QLauncher
Gui, Font, s17 Bold
Gui, Add, Button,   x10   y140 w205  h28 gScript112		 , Noodknop !
Gui, Show, y630 x1020 , Quicklauncher


WinSet, Transparent, 20, % "ahk_id " GuiHwnd
OnMessage("0x200", "MOUSEOVER")


MOUSEOVER(){
	Global GuiHwnd
	MouseGetPos, , , Hwnd
	if(Hwnd = GuiHwnd){
		WinSet, Transparent, 255, % "ahk_id " GuiHwnd
		SetTimer, MOUSELEAVE, 20
	}
}

MOUSELEAVE(){
	Global GuiHwnd
	MouseGetPos, , , Hwnd
	if(Hwnd != GuiHwnd){
		WinSet, Transparent, 1, % "ahk_id " GuiHwnd
		SetTimer, MOUSELEAVE, Off
	}
}

Script1:
	Loop
	{
		IfWinNotExist, SRT Cloud afmelden.ahk
		run, %PathToScript1%
		Sleep, 500
		break
	}
	SendLevel,1
	Send, {LWin down}{a down}
	Send, {LWin up}{a up}
	return

Script2:
	
	Loop
	{
		IfWinNotExist, TSI Cloud afmelden.ahk
		run, %PathToScript2%
		Sleep, 500
		;gui, show
		break
	}
		
	
	SendLevel,1
	Send, {LWin down}{t down}
	Send, {LWin up}{t up}
	return

Script3:
	Loop
	{
		IfWinNotExist, srt picklists v2.1.ahk
		run, %PathToScript3%
		Sleep, 500
		break
	}
	SendLevel,1
	Send, {LWin down}{p down}
	Send, {LWin up}{p up}
	return	

Script4:
	Loop
	{
		IfWinNotExist, tsi picklists v2.ahk
		run, %PathToScript4%
		Sleep, 500
		break
	}
	
SendLevel,1
	Send, {LWin down}{k down}
	Send, {LWin up}{k up}
	return	

Script5:
	SendLevel,1
	Send, {LWin down}{q down}
	Send, {LWin up}{q up}
	return	
	
Script6:
	SendLevel,1
	Send, {LWin down}{r down}
	Send, {LWin up}{r up}
	return	
	
	
Script6b:
		IfWinNotExist, hotkeys.ahk v1.0.ahk
		run, %PathToScript6b%
		Sleep, 500
		
	return	
	
Script7:

	SetWorkingDir, \\Winschoten\Verkooporder
	run, %PathToScript7% ; \\WINSCHOTEN\Verkooporder\Salesorder.exe, \\WINSCHOTEN\Verkooporder
	SetWorkingDir, %A_ScriptDir%
	MsGbox, %A_ScriptDir%
	return
	
Script8:
	Loop
		{
			IfWinNotExist, order importeren CLOUDVERSIE.ahk
			run, %PathToScript8%
			Sleep, 500
			gui, show
			break
		}
	
	SendLevel,1
	Send, {LWin down}{o down}
	Send, {LWin up}{o up}
	return	
	
Script9:
	Reload
	return

Script112:
	DetectHiddenWindows, On 
	WinGet, List, List, ahk_class AutoHotkey 

	Loop %List% 
	  { 
		WinGet, PID, PID, % "ahk_id " List%A_Index% 
		If ( PID <> DllCall("GetCurrentProcessId") ) 
			 PostMessage,0x111,65405,0,, % "ahk_id " List%A_Index% 
	  }
	
GuiClose:
ExitApp
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Why is the first button firing automatically  Topic is solved

19 May 2017, 09:54

It does not sometimes do it, it always does it. You are missing a return statement.

Once the code hits the line OnMessage("0x200", "MOUSEOVER"), it does not stop!

It skips MOUSEOVER() and MOUSELEAVE() and then hits the label Script1: which DOES NOT stop execution.

So add a return statement on the line after OnMessage("0x200", "MOUSEOVER")
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Why is the first button firing automatically

19 May 2017, 14:32

Aaaarg! Totally overlooked that. I was ging nuts.
Thanks mate.

(By the way, I never said it was happening sometimes ;) ).
Last edited by WalkerOfTheDay on 19 May 2017, 15:47, edited 1 time in total.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: dipahk, Nerafius, RandomBoy and 173 guests