press key
This commit is contained in:
parent
454544bb36
commit
a0d69ffca8
@ -6,9 +6,12 @@ require (
|
||||
github.com/micmonay/keybd_event v1.1.2
|
||||
github.com/r3labs/sse/v2 v2.10.0
|
||||
golang.org/x/sys v0.12.0
|
||||
golang.org/x/text v0.7.0
|
||||
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
|
||||
github.com/stretchr/testify v1.8.4 // indirect
|
||||
golang.org/x/net v0.6.0 // indirect
|
||||
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
|
||||
|
@ -3,6 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/micmonay/keybd_event v1.1.2 h1:RpgvPJKOh4Jc+ZYe0OrVzGd2eNMCfuVg3dFTCsuSah4=
|
||||
github.com/micmonay/keybd_event v1.1.2/go.mod h1:CGMWMDNgsfPljzrAWoybUOSKafQPZpv+rLigt2LzNGI=
|
||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
|
||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/r3labs/sse/v2 v2.10.0 h1:hFEkLLFY4LDifoHdiCN/LlGBAdVJYsANaLqNYa1l/v0=
|
||||
@ -19,9 +21,13 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
|
||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
gopkg.in/cenkalti/backoff.v1 v1.1.0 h1:Arh75ttbsvlpVA7WtVpH4u9h6Zl46xuptxqLxPiSo4Y=
|
||||
gopkg.in/cenkalti/backoff.v1 v1.1.0/go.mod h1:J6Vskwqd+OMVJl8C33mmtxTBs2gyzfv7UDAkHu8BrjI=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2 h1:MZF6J7CV6s/h0HBkfqebrYfKCVEo5iN+wzE4QhV3Evo=
|
||||
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2/go.mod h1:s1Sn2yZos05Qfs7NKt867Xe18emOmtsO3eAKbDaon0o=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
96
go/rcmd_ppt.go
Normal file
96
go/rcmd_ppt.go
Normal file
@ -0,0 +1,96 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/r3labs/sse/v2"
|
||||
"golang.org/x/text"
|
||||
"gopkg.in/toast.v1"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
deviceId := os.Getenv("DEVICE_ID")
|
||||
if deviceId == "" {
|
||||
println("DEVICE_ID env is not set")
|
||||
os.Exit(1)
|
||||
}
|
||||
pushNotification("连接", "开始连接。")
|
||||
|
||||
for {
|
||||
fmt.Println("开始连接。")
|
||||
pushNotification("连接", "开始连接。")
|
||||
client := sse.NewClient("https://ivampiresp.com/wp-content/rCMD/sse.php?device=" + deviceId)
|
||||
|
||||
err := client.Subscribe("message", func(msg *sse.Event) {
|
||||
//fmt.Println(msg.Data)
|
||||
|
||||
// byte to json
|
||||
var data map[string]interface{}
|
||||
err := json.Unmarshal(msg.Data, &data)
|
||||
|
||||
//fmt.Println(data)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
if data["cmd"] == nil || data["cmd"] == "" {
|
||||
//fmt.Println("cmd or params is nil")
|
||||
return
|
||||
}
|
||||
|
||||
// interface to string
|
||||
command := fmt.Sprintf("%v", data["cmd"])
|
||||
params := fmt.Sprintf("%v", data["param"])
|
||||
|
||||
if command != "press" {
|
||||
fmt.Println("此程序只作为演示工具使用,只处理 press 情况,但是意外的接收到了 " + command + ", 所以将不会处理。")
|
||||
return
|
||||
}
|
||||
|
||||
if params == "back" {
|
||||
pushNotification("返回", "返回。")
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
// 下个循环重新连接
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func pushNotification(title string, message string) {
|
||||
//notification := toast.Notification{
|
||||
// AppID: "手势操作",
|
||||
// Title: title,
|
||||
// Message: message,
|
||||
// //Icon: "go.png"
|
||||
// //Actions: []toast.Action{
|
||||
// // {"protocol", "I'm a button", ""},
|
||||
// // {"protocol", "Me too!", ""},
|
||||
// //},
|
||||
//}
|
||||
|
||||
utf8Reader := transform.NewReader(resp.Body, simplifiedchinese.GBK.NewDecoder())
|
||||
|
||||
notification := toast.Notification{
|
||||
AppID: "ExampleApp",
|
||||
Title: title,
|
||||
Message: "Some message about how important something is...",
|
||||
//Icon: "C:\\project\\notification\\notification\\assets\\icon.png",
|
||||
//Actions: []toast.Action{
|
||||
// {Type: "protocol", Label: "I'm a button", Arguments: ""},
|
||||
// {Type: "protocol", Label: "Me too!", Arguments: ""},
|
||||
//},
|
||||
}
|
||||
err := notification.Push()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user