-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssdisplay.go
More file actions
114 lines (108 loc) · 3.7 KB
/
ssdisplay.go
File metadata and controls
114 lines (108 loc) · 3.7 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"fmt"
"path/filepath"
"time"
"github.com/AlecAivazis/survey/v2"
"github.com/go-toast/toast"
"github.com/go-vgo/robotgo"
)
func takeScreenshot(fileName string, displayNum int) {
robotgo.DisplayID = displayNum
img, err := robotgo.CaptureImg()
if err != nil {
fmt.Println(err)
return
}
robotgo.Save(img, fileName)
CopyImgToClipboard(img)
}
func Screenshot_Display() {
active_displays := robotgo.DisplaysNum()
if active_displays == 1 {
_, _, w, h := robotgo.GetDisplayBounds(0)
fileName := filepath.Join(config.SaveLocation, fmt.Sprintf("Screenshot_%s_%dx%d.png", time.Now().Format("20060102_150405"), w, h))
takeScreenshot(fileName, 0)
fmt.Printf("Screenshot saved at %s", fileName)
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()
return
}
displays := []string{"Screenshot all displays", "Display 1 (Primary)"}
for i := 2; i < active_displays; i++ {
displays = append(displays, fmt.Sprintf("Display %d", i))
}
var display int
err := survey.AskOne(&survey.Select{
Message: "Select Display",
Options: displays,
}, &display, survey.WithValidator(survey.Required))
if err != nil {
fmt.Print("Some error occurred")
return
}
switch display {
case 0:
for i := range active_displays {
_, _, w, h := robotgo.GetDisplayBounds(i)
fileName := filepath.Join(config.SaveLocation, fmt.Sprintf("Screenshot_Disp%d_%s_%dx%d.png", i+1, time.Now().Format("20060102_150405"), w, h))
takeScreenshot(fileName, i)
fmt.Printf("Screenshot saved at %s", fileName)
}
notification := toast.Notification{
AppID: "Captr",
Title: fmt.Sprintf("%d Screenshot(s) Captured", active_displays),
Message: fmt.Sprintf("Screenshot saved at %s", config.SaveLocation),
ActivationArguments: config.SaveLocation,
Audio: toast.IM,
Actions: []toast.Action{
{Type: "protocol", Label: "Open Folder", Arguments: config.SaveLocation},
},
}
notification.Push()
case 1:
_, _, w, h := robotgo.GetDisplayBounds(0)
fileName := filepath.Join(config.SaveLocation, fmt.Sprintf("Screenshot_Disp%d_%s_%dx%d.png", 1, time.Now().Format("20060102_150405"), w, h))
takeScreenshot(fileName, 0)
fmt.Printf("Screenshot saved at %s", fileName)
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()
default:
_, _, w, h := robotgo.GetDisplayBounds(display - 1)
fileName := filepath.Join(config.SaveLocation, fmt.Sprintf("Screenshot_Disp%d_%s_%dx%d.png", display, time.Now().Format("20060102_150405"), w, h))
takeScreenshot(fileName, display-1)
fmt.Printf("Screenshot saved at %s", fileName)
notification := toast.Notification{
AppID: "Captr",
Title: fmt.Sprintf("Screenshot Captured of Display %d", display),
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()
}
}