-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsswindow.go
More file actions
54 lines (51 loc) · 1.52 KB
/
Copy pathsswindow.go
File metadata and controls
54 lines (51 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"path/filepath"
"syscall"
"time"
"unsafe"
"github.com/go-toast/toast"
"github.com/go-vgo/robotgo"
"github.com/tailscale/win"
)
func Screenshot_Window() {
hwnd := chooseWindow()
var pid uintptr = 0
user32 := syscall.MustLoadDLL("user32.dll")
prc := user32.MustFindProc("GetWindowThreadProcessId")
_, _, _ = prc.Call(uintptr(hwnd), uintptr(unsafe.Pointer(&pid)))
err := SetProcessDPIAware()
if err != nil {
fmt.Printf("Warning: Could not set DPI awareness: %v\n", err)
}
robotgo.ActivePid(int(pid))
robotgo.SetActiveWindow(win.HWND(hwnd))
ActivateWindowAndGetBounds(uintptr(hwnd))
bounds, _, _, err := GetWindowBoundsWithDPIInfo(uintptr(hwnd))
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
img, err := robotgo.CaptureImg(int(bounds.X), int(bounds.Y), int(bounds.Width), int(bounds.Height))
if err != nil {
fmt.Println("Cannot capture screenshot")
return
}
filename := filepath.Join(config.SaveLocation, fmt.Sprintf("Screenshot_%s.png", time.Now().Format("20060102_150405")))
robotgo.Save(img, filename)
fmt.Printf("Screenshot saved at %s", filename)
CopyImgToClipboard(img)
notification := toast.Notification{
AppID: "Captr",
Title: "Screenshot Captured",
Message: fmt.Sprintf("Screenshot saved at %s", filename),
Icon: filename,
ActivationArguments: filename,
Audio: toast.IM,
Actions: []toast.Action{
{Type: "protocol", Label: "Open", Arguments: filename},
},
}
notification.Push()
}