Compare commits
No commits in common. "576e70a989bdb71963911eadd4f1611c6ba6e0f7" and "daf414adbb3d8aa55618712b40f5d20ffe3ff5bb" have entirely different histories.
576e70a989
...
daf414adbb
30
Client.md
30
Client.md
@ -38,7 +38,6 @@ The base64 authentication token is loaded from the environment variable `KEYBOAR
|
|||||||
|
|
||||||
@{load connection URL from second CLI argument}
|
@{load connection URL from second CLI argument}
|
||||||
@{get authTokenInput from environment}
|
@{get authTokenInput from environment}
|
||||||
@{add xdotool if non qwerty function}
|
|
||||||
|
|
||||||
if !authTokenInputExists {
|
if !authTokenInputExists {
|
||||||
fmt.Print("Enter authentication token: ")
|
fmt.Print("Enter authentication token: ")
|
||||||
@ -95,15 +94,11 @@ if !strings.HasPrefix(connectionURL, "ws://") && !strings.HasPrefix(connectionUR
|
|||||||
--- start client with fifo
|
--- start client with fifo
|
||||||
|
|
||||||
|
|
||||||
var inputString string
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
input, err := ioutil.ReadFile(clientFifoInputFile)
|
input, err := ioutil.ReadFile(clientFifoInputFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
inputString = addXDoToolIfNonQWERTY(string(input))
|
|
||||||
input = []byte(inputString)
|
|
||||||
if len(input) > 0 {
|
if len(input) > 0 {
|
||||||
fmt.Println("send" + strings.Replace(string(input), " ", "space", 10))
|
fmt.Println("send" + strings.Replace(string(input), " ", "space", 10))
|
||||||
err = client.WriteMessage(websocket.TextMessage, input)
|
err = client.WriteMessage(websocket.TextMessage, input)
|
||||||
@ -134,7 +129,7 @@ for {
|
|||||||
|
|
||||||
|
|
||||||
rune, _, err := reader.ReadRune() //:= fmt.Scan(&key)
|
rune, _, err := reader.ReadRune() //:= fmt.Scan(&key)
|
||||||
key = addXDoToolIfNonQWERTY(string(rune))
|
key = string(rune)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
@ -151,27 +146,4 @@ for {
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
# Handling unicode outside of the ASCII set
|
|
||||||
|
|
||||||
``` go
|
|
||||||
|
|
||||||
--- add xdotool if non qwerty function --- noWeave
|
|
||||||
addXDoToolIfNonQWERTY := func(message string)(string) {
|
|
||||||
if strings.HasPrefix(message, "{kb_cmd:xdotool}:") {
|
|
||||||
return message
|
|
||||||
}
|
|
||||||
for _, char := range message {
|
|
||||||
if char < 32 || char > 126 {
|
|
||||||
if char != 8 && char != 9 && char != 10 {
|
|
||||||
return "{kb_cmd:xdotool}:" + message
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return message
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
```
|
```
|
61
Streaming.md
61
Streaming.md
@ -14,6 +14,8 @@ To specify xdotool usage, the client should send a message with the format `{kb_
|
|||||||
func clientConnected(w http.ResponseWriter, r *http.Request) {
|
func clientConnected(w http.ResponseWriter, r *http.Request) {
|
||||||
keyboard, err := sendkeys.NewKBWrapWithOptions(sendkeys.Noisy)
|
keyboard, err := sendkeys.NewKBWrapWithOptions(sendkeys.Noisy)
|
||||||
|
|
||||||
|
// regex if string has characters we need to convert to key presses
|
||||||
|
characterRegex, _ := regexp.Compile(`[^\x08]\x08|\t|\n`)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -61,23 +63,14 @@ func clientConnected(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
# Sending the keys
|
# Sending the keys
|
||||||
|
|
||||||
Sending the keys is a bit tricky as we need to manually convert backspace, tab, enter and modifier keys.
|
Sending the keys is a bit tricky as we need to manually convert backspace, tab, and enter.
|
||||||
|
|
||||||
``` go
|
``` go
|
||||||
|
|
||||||
--- send keys to system
|
--- send keys to system
|
||||||
|
|
||||||
|
|
||||||
// regex if string has characters we need to convert to key presses
|
|
||||||
characterRegex, _ := regexp.Compile(`[^\x08]\x08|\t|\n`)
|
|
||||||
|
|
||||||
doXDoTool := func(command string, keys string)(err error) {
|
doXDoTool := func(command string, keys string)(err error) {
|
||||||
var cmd *exec.Cmd
|
cmd := exec.Command("xdotool", command, keys)
|
||||||
if command == "type" {
|
|
||||||
cmd = exec.Command("xdotool", command, "--delay", "25", keys)
|
|
||||||
} else {
|
|
||||||
cmd = exec.Command("xdotool", command, keys)
|
|
||||||
}
|
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,43 +94,33 @@ if strings.HasPrefix(message_string, "{kb_cmd:xdotool}:") {
|
|||||||
doXDoTool("type", charString)
|
doXDoTool("type", charString)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// key is required for special characters
|
|
||||||
err = doXDoTool("key", charString)
|
err = doXDoTool("key", charString)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
} else {
|
|
||||||
doXDoTool("type", message_string)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doXDoTool("type", message_string)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if characterRegex.MatchString(message_string) {
|
for _, character := range message_string {
|
||||||
for _, character := range message_string {
|
charString := string(character)
|
||||||
charString := string(character)
|
if charString == "\n" {
|
||||||
if charString == "\n" {
|
keyboard.Enter()
|
||||||
keyboard.Enter()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if charString == "\t" {
|
|
||||||
keyboard.Tab()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if charString == "\b" {
|
|
||||||
keyboard.BackSpace()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
err = keyboard.Type(charString)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("type:", err)
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
continue
|
if charString == "\t" {
|
||||||
}
|
keyboard.Tab()
|
||||||
err = keyboard.Type(message_string)
|
continue
|
||||||
if err != nil {
|
}
|
||||||
log.Println("type:", err)
|
if charString == "\b" {
|
||||||
|
keyboard.BackSpace()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
err = keyboard.Type(charString)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("type:", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
---
|
---
|
||||||
```
|
```
|
Loading…
Reference in New Issue
Block a user