From f21060d8a39791df63bfe6a3d6c001b872ad3468 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Mon, 27 Nov 2023 19:18:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/go.mod => go.mod | 0 go/go.sum => go.sum | 0 go/rcmd_ppt.go | 96 ----------------------- config.php => php/config.php | 0 get.php => php/get.php | 0 send.php => php/send.php | 0 sse.php => php/sse.php | 0 go/pressKey.go => pressKey.go | 3 +- rcmd_ppt.go | 138 ++++++++++++++++++++++++++++++++++ go/start.bat => start.bat | 0 go/win.go => win.go | 0 11 files changed, 140 insertions(+), 97 deletions(-) rename go/go.mod => go.mod (100%) rename go/go.sum => go.sum (100%) delete mode 100644 go/rcmd_ppt.go rename config.php => php/config.php (100%) rename get.php => php/get.php (100%) rename send.php => php/send.php (100%) rename sse.php => php/sse.php (100%) rename go/pressKey.go => pressKey.go (99%) create mode 100644 rcmd_ppt.go rename go/start.bat => start.bat (100%) rename go/win.go => win.go (100%) diff --git a/go/go.mod b/go.mod similarity index 100% rename from go/go.mod rename to go.mod diff --git a/go/go.sum b/go.sum similarity index 100% rename from go/go.sum rename to go.sum diff --git a/go/rcmd_ppt.go b/go/rcmd_ppt.go deleted file mode 100644 index 17b8adc..0000000 --- a/go/rcmd_ppt.go +++ /dev/null @@ -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) - } - -} diff --git a/config.php b/php/config.php similarity index 100% rename from config.php rename to php/config.php diff --git a/get.php b/php/get.php similarity index 100% rename from get.php rename to php/get.php diff --git a/send.php b/php/send.php similarity index 100% rename from send.php rename to php/send.php diff --git a/sse.php b/php/sse.php similarity index 100% rename from sse.php rename to php/sse.php diff --git a/go/pressKey.go b/pressKey.go similarity index 99% rename from go/pressKey.go rename to pressKey.go index 29bbe7a..34d37be 100644 --- a/go/pressKey.go +++ b/pressKey.go @@ -1,9 +1,10 @@ package main import ( - "github.com/micmonay/keybd_event" "runtime" "time" + + "github.com/micmonay/keybd_event" ) func main() { diff --git a/rcmd_ppt.go b/rcmd_ppt.go new file mode 100644 index 0000000..1f2102c --- /dev/null +++ b/rcmd_ppt.go @@ -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) +// } + +// } diff --git a/go/start.bat b/start.bat similarity index 100% rename from go/start.bat rename to start.bat diff --git a/go/win.go b/win.go similarity index 100% rename from go/win.go rename to win.go