改进
This commit is contained in:
parent
a0d69ffca8
commit
f21060d8a3
@ -1,96 +0,0 @@
|
|||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,9 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/micmonay/keybd_event"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/micmonay/keybd_event"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
138
rcmd_ppt.go
Normal file
138
rcmd_ppt.go
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/micmonay/keybd_event"
|
||||||
|
"github.com/r3labs/sse/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
deviceId := os.Getenv("DEVICE_ID")
|
||||||
|
if deviceId == "" {
|
||||||
|
println("DEVICE_ID env is not set")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
// pushNotification("连接", "开始连接。")
|
||||||
|
|
||||||
|
for {
|
||||||
|
fmt.Println("开始连接。")
|
||||||
|
// pushNotification("Connected", "Connected")
|
||||||
|
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"])
|
||||||
|
param := fmt.Sprintf("%v", data["param"])
|
||||||
|
|
||||||
|
if command != "press" {
|
||||||
|
fmt.Println("此程序只作为演示工具使用,只处理 press 情况,但是意外的接收到了 " + command + ", 所以将不会处理。")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("按下: " + param)
|
||||||
|
|
||||||
|
if param == "up" {
|
||||||
|
pressKey(keybd_event.VK_UP)
|
||||||
|
}
|
||||||
|
|
||||||
|
if param == "down" {
|
||||||
|
pressKey(keybd_event.VK_DOWN)
|
||||||
|
}
|
||||||
|
|
||||||
|
if param == "left" {
|
||||||
|
pressKey(keybd_event.VK_LEFT)
|
||||||
|
}
|
||||||
|
|
||||||
|
if param == "right" {
|
||||||
|
pressKey(keybd_event.VK_RIGHT)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
// 下个循环重新连接
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func pressKey(key int) {
|
||||||
|
kb, err := keybd_event.NewKeyBonding()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// For linux, it is very important to wait 2 seconds
|
||||||
|
if runtime.GOOS == "linux" {
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select keys to be pressed
|
||||||
|
kb.SetKeys(key)
|
||||||
|
|
||||||
|
// Set shift to be pressed
|
||||||
|
kb.HasSHIFT(false)
|
||||||
|
|
||||||
|
// Press the selected keys
|
||||||
|
err = kb.Launching()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// // Or you can use Press and Release
|
||||||
|
// kb.Press()
|
||||||
|
// time.Sleep(1 * time.Millisecond)
|
||||||
|
// kb.Release()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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!", ""},
|
||||||
|
// // //},
|
||||||
|
// //}
|
||||||
|
|
||||||
|
// 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