-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (59 loc) · 1.23 KB
/
main.go
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
package main
import (
"fmt"
"os"
"os/signal"
//"sync"
"time"
"golang.org/x/sys/windows"
)
var (
moduser32 = windows.NewLazyDLL("user32.dll")
procGetAsyncKeyState = moduser32.NewProc("GetAsyncKeyState")
)
func main() {
fmt.Println("Start")
countdown()
}
func countdown(){
t := time.NewTicker(1 * time.Second)
defer t.Stop()
reset := make(chan int, 1)
reset <- 0
go func (){
for {
// If you want to change the value of the key, please refer to the URL.
// https://docs.microsoft.com/ja-jp/windows/win32/inputdev/virtual-key-codes?redirectedfrom=MSDN
button01, _, _ := procGetAsyncKeyState.Call(uintptr(0x05))
button02, _, _ := procGetAsyncKeyState.Call(uintptr(0x06))
if button01 == 0 || button02 == 0 {
reset <- 0
continue
}
fmt.Printf("\r!!")
reset <- 1
}
}()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func (){
select {
case <-c:
fmt.Printf("\n")
t.Stop()
close(reset)
close(c)
os.Exit(130)
return
}
}()
for i := 15; true; i-- {
select {
case <-t.C:
fmt.Printf("\r%2d",i)
}
if <- reset != 0 || i < 1 {
i = 14
}
}
}