Keep script running after closing a window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Ataricx
Posts: 34
Joined: 24 Feb 2019, 06:12

Keep script running after closing a window

20 Apr 2019, 04:23

I got this script working good, except for this section:

Code: Select all

:*:iiii::
#NoEnv
#SingleInstance Force
SetBatchLines -1

myTxtFile = 
(
info1 |txt1
info2 |txt2
)

Gui Add, ListView, r45 w800 Grid gLvHandler +HWNDhLV, Omschrijving|Info1|Info2|Info3|Info4
for each, Line in StrSplit(myTxtFile, "`n", "`r")
{
	Columns := StrSplit(Line, "|")
	LV_Add("", Columns*)
}
LV_ModifyCol()
Gui Show
Return

GuiClose:
GuiEscape:
	ExitApp
Return

LvHandler:
	if (A_GuiEvent == "DoubleClick")
	{
		Row := A_EventInfo
		Col := LV_SubitemHitTest(hLV)

		LV_GetText(result, Row, Col)
		Clipboard := result

		Tooltip % "Klembord: " Clipboard

	}
Sleep, 2000
ToolTip
Return

LV_SubitemHitTest(HLV) {
   Static LVM_SUBITEMHITTEST := 0x1039
   VarSetCapacity(POINT, 8, 0)
   DllCall("User32.dll\GetCursorPos", "Ptr", &POINT)
   DllCall("User32.dll\ScreenToClient", "Ptr", HLV, "Ptr", &POINT)
   VarSetCapacity(LVHITTESTINFO, 24, 0)
   NumPut(NumGet(POINT, 0, "Int"), LVHITTESTINFO, 0, "Int")
   NumPut(NumGet(POINT, 4, "Int"), LVHITTESTINFO, 4, "Int")
   SendMessage, LVM_SUBITEMHITTEST, 0, &LVHITTESTINFO, , ahk_id %HLV%
   If (ErrorLevel = -1)
      Return 0
   Subitem := NumGet(LVHITTESTINFO, 16, "Int") + 1
   Return Subitem
}
when i launch the whole script, everything is working but after i closed the windows which was opened through "iiii" and try to launch it again by pressing the 'iiii' again, the window doesnt pop up anymore..... i have to relaunch the whole script again to get it working again, because every script which i was using is closed by this script.

When i delete the section above, the script stays running in the background.

Hopefully you'll understand.

Here is the whole script:

Code: Select all

#SingleInstance, force 
#Persistent

Menu, Tray, Icon, Shell32.dll, 150
Menu, Tray, Tip, Menu 2019

UMDelay = 10

Menu, klapmenu_systeem, Add, Open cache mappen, open_temp_folders
Menu, MijnMenu, Add, Systeem, :klapmenu_systeem

; -------------------------------------------------------------------------
Menu, MijnMenu, Color, dbdbdb
return
; ---------------------------------------------------------------------------------------------------

open_temp_folders:
run cmd.exe
return

~MButton::
HowLong = 0
Loop
{
	HowLong ++
	Sleep, 40
	GetKeyState, MButton, MButton, P
	IfEqual, MButton, U, Break
}
IfLess, HowLong, %UMDelay%, Return
; ---------------------------------------------------------------------------------------------------
F7::Menu, MijnMenu, Show
; ---------------------------------------------------------------------------------------------------


:*:iiii::
#NoEnv
#SingleInstance Force
SetBatchLines -1

myTxtFile = 
(
info1 |txt1
info2 |txt2
)

Gui Add, ListView, r45 w800 Grid gLvHandler +HWNDhLV, Omschrijving|Info1|Info2|Info3|Info4
for each, Line in StrSplit(myTxtFile, "`n", "`r")
{
	Columns := StrSplit(Line, "|")
	LV_Add("", Columns*)
}
LV_ModifyCol()
Gui Show
Return

GuiClose:
GuiEscape:
	ExitApp
Return

LvHandler:
	if (A_GuiEvent == "DoubleClick")
	{
		Row := A_EventInfo
		Col := LV_SubitemHitTest(hLV)

		LV_GetText(result, Row, Col)
		Clipboard := result

		Tooltip % "Klembord: " Clipboard

	}
Sleep, 2000
ToolTip
Return

LV_SubitemHitTest(HLV) {
   Static LVM_SUBITEMHITTEST := 0x1039
   VarSetCapacity(POINT, 8, 0)
   DllCall("User32.dll\GetCursorPos", "Ptr", &POINT)
   DllCall("User32.dll\ScreenToClient", "Ptr", HLV, "Ptr", &POINT)
   VarSetCapacity(LVHITTESTINFO, 24, 0)
   NumPut(NumGet(POINT, 0, "Int"), LVHITTESTINFO, 0, "Int")
   NumPut(NumGet(POINT, 4, "Int"), LVHITTESTINFO, 4, "Int")
   SendMessage, LVM_SUBITEMHITTEST, 0, &LVHITTESTINFO, , ahk_id %HLV%
   If (ErrorLevel = -1)
      Return 0
   Subitem := NumGet(LVHITTESTINFO, 16, "Int") + 1
   Return Subitem
}
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: Keep script running after closing a window

20 Apr 2019, 05:30

It's because you have:

Code: Select all

GuiClose:
GuiEscape:
	ExitApp
Return
That tells the script to exit when you close the GUI.

It sounds like you want to close the GUI without exiting the script, in which case you probably want:

Code: Select all

GuiClose:
GuiEscape:
	Gui, Hide
Return
Ataricx
Posts: 34
Joined: 24 Feb 2019, 06:12

Re: Keep script running after closing a window

20 Apr 2019, 06:41

@Osprey
thank you very much, that does the trick :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Fredrik F, maxkill, RandomBoy, ShatterCoder and 403 guests