-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsound.go
More file actions
53 lines (47 loc) · 1.1 KB
/
Copy pathsound.go
File metadata and controls
53 lines (47 loc) · 1.1 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
// sound.go - Capture Sound Effect
//
// Plays the Windows system notification sound (SystemAsterisk) as audio
// feedback when a screenshot is captured. Uses winmm.dll PlaySoundW.
package main
import (
"syscall"
"unsafe"
)
var (
winmm = syscall.NewLazyDLL("winmm.dll")
procPlaySound = winmm.NewProc("PlaySoundW")
)
const (
sndAlias = 0x00010000
sndAsync = 0x00000001
sndNoDefault = 0x00000002
)
// PlayCaptureSound plays the system notification sound. Non-blocking.
func PlayCaptureSound() {
go func() {
name, _ := syscall.UTF16PtrFromString("SystemAsterisk")
procPlaySound.Call(
uintptr(unsafe.Pointer(name)),
0,
sndAlias|sndAsync|sndNoDefault,
)
}()
}
const (
sndFilename = 0x00020000
)
// PlayKillSound plays the user-configured WAV file for kill notifications.
// Non-blocking. Does nothing if path is empty or file doesn't exist.
func PlayKillSound(wavPath string) {
if wavPath == "" {
return
}
go func() {
path, _ := syscall.UTF16PtrFromString(wavPath)
procPlaySound.Call(
uintptr(unsafe.Pointer(path)),
0,
sndFilename|sndAsync|sndNoDefault,
)
}()
}