Adding increments to filename Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
panhartstuff
Posts: 20
Joined: 21 Jan 2018, 07:40

Adding increments to filename

02 Aug 2018, 06:54

https://autohotkey.com/boards/viewtopic.php?t=2237
I'm trying the code from the above thread

Code: Select all

#SingleInstance, Force
#NoEnv
SetBatchLines, -1
OnExit, Exit
FileOut := A_Desktop "\MyNewFile.png"

; Uncomment if Gdip.ahk is not in your standard library
; #Include, Gdip.ahk
if (!pToken := Gdip_Startup()) {
	MsgBox, 48, Gdiplus error!, Gdiplus failed to start. Please ensure you have Gdiplus on your system.
	ExitApp
}
return

^#s::
WinHwnd := WinActive("A")
DllCall("SetWindowPos"
    , "UInt", WinHwnd
    , "UInt", 0        ; hWndInsertAfter
    , "Int" , 0        ; X
    , "Int" , 0        ; Y
    , "Int" , 840      ; cx (width)
    , "Int" , 1500     ; cy (height)
    , "UInt", 4|0x400) ; uFlags

pBitmap := Gdip_BitmapFromHWND(WinHwnd)
, Gdip_SaveBitmapToFile(pBitmap, FileOut)
, Gdip_DisposeImage(pBitmap)
Run, % FileOut
return

Esc::
Exit:
Gdip_Shutdown(pToken)
ExitApp
What I want to do is make it take screenshots every few seconds, appending an increment to the filename everytime. But I can't find a way to increment the filename, can someone help me with this? I tried to add %a_now%, but it doesn't work

Also another question, when I tried to install the latest Gdip library (from https://autohotkey.com/boards/viewtopic.php?t=6517), I needed to rename it to Gdip.ahk (originally Gdip_All.ahk) for the script to work. Why is that?
MannyKSoSo
Posts: 439
Joined: 28 Apr 2018, 21:59

Re: Adding increments to filename  Topic is solved

02 Aug 2018, 07:37

For the increment of the file name change the position of FileOut to be contained within the hot key (add it to the top just to make sure it changes). Then change that line to this FileOut := A_Desktop "\MyNewFile" Increment ".png" and finally add two more lines of code, the first is anywhere before the hotkey add Increment := 1 (so you start at 1) and after Run, % FileOut add a new line with Increment ++ to add 1 to the increment number. As for the Gdip name its because of the Includes, it is expecting a file name of Gdip not Gdip_All (which is why you had to change the file name).
panhartstuff
Posts: 20
Joined: 21 Jan 2018, 07:40

Re: Adding increments to filename

02 Aug 2018, 07:46

Code: Select all

#SingleInstance, Force
#NoEnv
SetBatchLines, -1
OnExit, Exit

; Uncomment if Gdip.ahk is not in your standard library
; #Include, Gdip.ahk
if (!pToken := Gdip_Startup()) {
	MsgBox, 48, Gdiplus error!, Gdiplus failed to start. Please ensure you have Gdiplus on your system.
	ExitApp
}
return

loop 
{
FileOut := A_Desktop "\MyNewFile" A_Now ".png"
WinHwnd := WinActive("A")
DllCall("SetWindowPos"
    , "UInt", WinHwnd
    , "UInt", 0        ; hWndInsertAfter
    , "Int" , 0        ; X
    , "Int" , 0        ; Y
    , "Int" , 840      ; cx (width)
    , "Int" , 1500     ; cy (height)
    , "UInt", 4|0x400) ; uFlags

pBitmap := Gdip_BitmapFromHWND(WinHwnd)
, Gdip_SaveBitmapToFile(pBitmap, FileOut)
, Gdip_DisposeImage(pBitmap)

Sleep, 2000
}

Esc::
Exit:
Gdip_Shutdown(pToken)
ExitApp
Alright thanks I managed to get the increments working but with dates instead. But the loop isn't working for some reason. When I run the script it takes a screenshot only once and it simply stopped there. What am I doing incorrectly?

EDIT:
Whoops, I'm an idiot that overlooked the thing you said about putting the FileOut within the loop. Thanks, it's working now!

Return to “Ask For Help”

Who is online

Users browsing this forum: enrica, Google [Bot], jmasiak, sdkyron and 240 guests