Reputation: 12940
I need to use Tcl to capture a screenshot of a given program not written with Tk (for example Firefox).
All I found is how to use Img
to capture Tk applications.
Any idea on how to do that?
Thanks
Upvotes: 0
Views: 614
Reputation: 23
You can find a useful information here (for Windows only.)
Take an example of "wish.exe" assuming that it's default title is "wish".
package require twapi
set pid [exec C:/Tcl/bin/wish.exe &]
set hwnd [twapi::find_windows -text "wish" -toplevel 1 -visible 1 -single]
twapi::set_focus $hwnd
twapi::send_keys {%{PRTSC}}; # type Alt+PrintScreen key
after 200; # avoid an access denied error.
set ts [clock format [clock seconds] -format "%Y%m%d%H%M%S"]
set filename "screenshotwin_$ts.bmp"
set phImg [Clipboard2Img]; # refer to the wiki page
$phImg write [file rootname $filename].png -format PNG
Or simply call nircmd. This is better than depending on the Alt+PrintScreen key.
exec C:/Tcl/bin/wish.exe &
after 100
exec nircmd.exe win activate title "wish"
after 100
exec nircmd.exe savescreenshotwin "screenshotwin.png"
Upvotes: 1