Can ahk take a screenshot of a window when it is hidden ?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
z1z123
Posts: 42
Joined: 04 Apr 2021, 19:47

Can ahk take a screenshot of a window when it is hidden ?

14 Sep 2023, 05:45

i need to screenshot noxplayer each x second, so that i can use the screen to do other things. If ahk can, can you help me ? And if ahk can't, are there any other software can do that ?
User avatar
mikeyww
Posts: 27370
Joined: 09 Sep 2014, 18:38

Re: Can ahk take a screenshot of a window when it is hidden ?

14 Sep 2023, 07:11

Timed background window screenshot

Code: Select all

/* Timed window screenshot ------------------------------------------------------
This script uses GDI+ to save screenshots of a window (foreground or background)
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=121434&p=539053#p539053
https://github.com/marius-sucan/AHK-GDIp-Library-Compilation
By mikeyww • For AutoHotkey version 1.1.37.01
14 September 2023
---------------------------------------------------------------------------------
*/
#Requires AutoHotkey v1.1.33
#Include d:\Q\vis2\lib\Gdip_All.ahk
winTitle := "ahk_class Notepad"      ; Target window
dir      := A_ScriptDir              ; Output directory for images
freq     := 1000                     ; Frequency (ms) of image capture
Global pBitmap, pToken := Gdip_Startup()
OnExit("done")                       ; Clean up upon exit

#If WinExist(winTitle)
F3::                                 ; F3 = Toggle timer for screenshots
If on := !on {
 SetTimer Capture, % freq            ; Schedule for image capture
 SoundBeep 1500
 Gosub Capture
 Return
}
Stop:
SetTimer Capture, Off
SoundBeep 1000
on := False
Return
#If

Capture:
If hWnd := WinExist(winTitle) {                         ; Get target window's HWND
 pBitmap := Gdip_BitmapFromHWND(hWnd)                   ; Get window's bitmap
 FormatTime ts,, yyMMdd-HHmmss                          ; Use timestamp in file name
 Gdip_SaveBitmapToFile(pBitmap, dir "\image" ts ".png") ; Save image file
 SoundBeep 2500
} Else Gosub Stop                                       ; Stop timer when window does not exist
Return

done(exitReason, exitCode) {
 If pBitmap
  Gdip_DisposeImage(pBitmap)
 Gdip_Shutdown(pToken)
 SoundBeep 1000
}
Last edited by mikeyww on 15 Sep 2023, 11:57, edited 3 times in total.
z1z123
Posts: 42
Joined: 04 Apr 2021, 19:47

Re: Can ahk take a screenshot of a window when it is hidden ?

14 Sep 2023, 07:40

2.png
2.png (137.99 KiB) Viewed 806 times
1.png
1.png (152.92 KiB) Viewed 806 times
Error.
And i have 2 noxplayer windows already running, how i can screenshot them using 1-2 your .ahk ?

Code: Select all

; This script uses GDI+ to save screenshots of a window (foreground or background)
; https://github.com/buliasz/AHKv2-Gdip
#Include C:\Users\admin\Desktop\abc\Gdip_All.ahk
winTitle := "ahk_exe notepad.exe"
dir      := A_ScriptDir
pToken   := Gdip_Startup()
OnExit("done")

#If WinExist(winTitle)
F3::
If on := !on {
 SetTimer Capture, 1000
 SoundBeep 1500
 Gosub Capture
 Return
}
Stop:
SetTimer Capture, Off
SoundBeep 1000
on := False
Return
#If

Capture:
If !win := WinExist(winTitle)
 Gosub Stop
FormatTime, ts,, yyMMdd-HHmmss
image   := Format("{}\image{}.png", dir, ts)
pBitmap := Gdip_BitmapFromHWND(win)
Gdip_SaveBitmapToFile(pBitmap, image)
SoundBeep 2500
Return

done(exitReason, exitCode) {
 If pBitmap
  Gdip_DisposeImage(pBitmap)
 Gdip_Shutdown(pToken)
 SoundBeep 1000
}
User avatar
mikeyww
Posts: 27370
Joined: 09 Sep 2014, 18:38

Re: Can ahk take a screenshot of a window when it is hidden ?

14 Sep 2023, 07:45

Try my latest update (edited above). This is the v1 forum.
User avatar
V0RT3X
Posts: 249
Joined: 20 May 2023, 21:59
Contact:

Re: Can ahk take a screenshot of a window when it is hidden ?

14 Sep 2023, 07:47

Good day Mikey!!
Was curious about this idea so had to give it a try of course. It may be my copies from when I found them, but for this script to work I had to switch Gdip_All.ahk for Gdip.ahk.
And while I am a big fan of soundbeep (thanks to you), That is all I have happening once I press F3. I get the intial beep, followed by the second beep every 1 second, but nothing showing up as images in the A_ScriptDir. Ideas?
User avatar
mikeyww
Posts: 27370
Joined: 09 Sep 2014, 18:38

Re: Can ahk take a screenshot of a window when it is hidden ?

14 Sep 2023, 07:49

Sorry I had posted the wrong URL (for v2), though still using Gdip_All.ahk in the #Include.

This is the URL: https://github.com/marius-sucan/AHK-GDIp-Library-Compilation.

Test with Notepad first. I updated my script to reflect the correct URL.

How do I work around problems caused by User Account Control (UAC)?
z1z123
Posts: 42
Joined: 04 Apr 2021, 19:47

Re: Can ahk take a screenshot of a window when it is hidden ?

14 Sep 2023, 08:18

oh i have to run as admin to work :D
now with nox i try this but not work

Code: Select all

winTitle := "ahk_class NoxVMHandle"      ; Target window

Code: Select all

winTitle := "ahk_class NoxVMHandleFrontend"      ; Target window

Code: Select all

winTitle := "ahk_class NoxVMHandle Frontend"      ; Target window

Code: Select all

winTitle := "ahk_class NoxPlayer"      ; Target window
image.png
image.png (10.79 KiB) Viewed 785 times
Attachments
image.png
image.png (9.03 KiB) Viewed 787 times
User avatar
mikeyww
Posts: 27370
Joined: 09 Sep 2014, 18:38

Re: Can ahk take a screenshot of a window when it is hidden ?

14 Sep 2023, 08:25

First question: does the script work with Notepad?
Last edited by mikeyww on 14 Sep 2023, 08:27, edited 2 times in total.
z1z123
Posts: 42
Joined: 04 Apr 2021, 19:47

Re: Can ahk take a screenshot of a window when it is hidden ?

14 Sep 2023, 08:25

mikeyww wrote:
14 Sep 2023, 08:25
First question: does the script work with Notepad?
yes sir :D
User avatar
mikeyww
Posts: 27370
Joined: 09 Sep 2014, 18:38

Re: Can ahk take a screenshot of a window when it is hidden ?

14 Sep 2023, 08:27

Run Window Spy to see the WinTitle information.

Some games block scripting.

You can also (alternatively) try ahk_exe with the process name.
z1z123
Posts: 42
Joined: 04 Apr 2021, 19:47

Re: Can ahk take a screenshot of a window when it is hidden ?

14 Sep 2023, 08:58

It blank, i guess nox block it, or it have other .exe for screen :D
Anyway, thank you, sir :D
image230914-204233.png
image230914-204233.png (16.25 KiB) Viewed 765 times

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Marium0505, Trunks298 and 174 guests