Wait for GUI input

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sinbad
Posts: 40
Joined: 01 Mar 2018, 09:32

Wait for GUI input

15 Dec 2018, 05:11

Good morning!

I want to monitor a folder for new png files and then popup a gui for data entry. I just cobbled this together with stuff from the forum to test, but the script keeps looping while the GUI is onscreen and then it complains about duplicate declarations.

Edit: This works but it feels like a fudge. Edit 2: and if it is a very large file it may not finish copying before the loop begins again...

Code: Select all

pngPath := "E:\1newImage\*.png"
tempPath := "E:\2tempImage"
renamedImagePath := "E:\3renamedImage\"

SetTimer, FolderMon, 10000
return

FolderMon:
Loop, %pngPath%
{
	FileCopy % pngPath, %tempPath%
	Sleep 100
	FileRecycle % pngPath
	Sleep 100
	goto GuiCreate
}
return

GuiCreate:
Gui Add, Edit, vTitle
Gui Add, Button, gSubmit, Submit
Gui Show
return

Submit:
Gui Submit
Gui Destroy
newFileName := Title ".png"
Sleep 100
tempFileFullPath := "E:\2tempImage\*.png"
newFileFullPath := renamedImagePath newFileName
msgbox % tempFileFullPath " " newFileFullPath
FileCopy % tempFileFullPath, %newFileFullPath%
Sleep 100 
Msgbox  % "new file name" newFileName
Last edited by sinbad on 15 Dec 2018, 10:37, edited 3 times in total.
neokix
Posts: 36
Joined: 10 May 2017, 07:50
Contact:

Re: Wait for GUI input

15 Dec 2018, 08:08

Hi. As far as I can see, probably you need to specify "Files" just after the Loop command.
In Help, it says,

Code: Select all

Loop, Files, FilePattern [, Mode]
https://autohotkey.com/docs/commands/LoopFile.htm

I hope it will prevent from looping.

But why do you need to use settimer if you want to loop the block all the time?
Maybe consider using Sleep instead. It probably makes simpler to manipulate.

Also, probably you need to find the way to remove the file, otherwise they may keep finding the same file.

So... let me know how it goes.
sinbad
Posts: 40
Joined: 01 Mar 2018, 09:32

Re: Wait for GUI input

15 Dec 2018, 10:17

neokix wrote:
15 Dec 2018, 08:08
Hi. As far as I can see, probably you need to specify "Files" just after the Loop command.
In Help, it says,

Code: Select all

Loop, Files, FilePattern [, Mode]
https://autohotkey.com/docs/commands/LoopFile.htm

I hope it will prevent from looping.

But why do you need to use settimer if you want to loop the block all the time?
Maybe consider using Sleep instead. It probably makes simpler to manipulate.

Also, probably you need to find the way to remove the file, otherwise they may keep finding the same file.

So... let me know how it goes.
Thanks neokix, I just cobbled together some pseudo-code with stuff found in the forum. I tried using loop,files but it made no difference. Anyway I just updated the code with something that actually works but I don't know if it's the best solution.
sinbad
Posts: 40
Joined: 01 Mar 2018, 09:32

Re: Wait for GUI input

15 Dec 2018, 10:38

I think my solution will fail if a large file takes more than 10 seconds to copy....
neokix
Posts: 36
Joined: 10 May 2017, 07:50
Contact:

Re: Wait for GUI input

16 Dec 2018, 06:44

Hi again. I'm still thinking that "SetTimer" command does nothing, because if the "Settimer"commands leads to the subroutine "Foldermon", it loops again and again without any incubation(?) period.

So, if I were you, I would try something like this without using SetTimer.

Code: Select all

Loop, %pngPath%
;or Loop, Files, %pngPath%, not sure.
{
	FileCopy % pngPath, %tempPath%
	Sleep 100
	FileRecycle % pngPath
	Sleep 100
	goto GuiCreate
	Sleep, 10000
}
return
Interesting script. I might use this for my work as well. Hope you will figure it out!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ccqcl, Descolada, Rohwedder and 179 guests