When the GoSmartKeyboard client is started, it does the following:
KEYBOARD_AUTH
or stdin if it does not exist.if len(os.Args) > 1 {
@{get client fifo input file from environment}
@{setup client}
if clientFifoInputFileEnvExists {
@{start client with fifo}
os.Exit(0)
}
@{start client with stdin}
os.Exit(0)
}
Used by 1
The base64 authentication token is loaded from the environment variable KEYBOARD_AUTH
, if it does not exist we read it from stdin (base64 encoded), ended with a newline.
@{load connection URL from second CLI argument}
@{get authTokenInput from environment}
@{add xdotool if non qwerty function}
if !authTokenInputExists {
fmt.Print("Enter authentication token: ")
_, err := fmt.Scanln(&authTokenInput)
if err != nil {
log.Fatal(err)
}
}
client, _, err := websocket.DefaultDialer.Dial(connectionURL, nil)
if err != nil {
log.Fatal("dial:", err)
}
defer client.Close()
err = client.WriteMessage(websocket.TextMessage, []byte(authTokenInput))
if err != nil {
log.Fatal("write:", err)
}
_, authResponse, err := client.ReadMessage()
if err != nil {
log.Fatal("read:", err)
}
if string(authResponse) == "authenticated" {
fmt.Println("authenticated")
} else {
log.Fatal("authentication failed")
}
Used by 1
var inputString string
syscall.Mkfifo(clientFifoInputFile, syscall.S_IFIFO|0666)
for {
input, err := ioutil.ReadFile(clientFifoInputFile)
if err != nil {
log.Fatal(err)
}
inputString = addXDoToolIfNonQWERTY(string(input))
input = []byte(inputString)
if len(input) > 0 {
fmt.Println("send" + strings.Replace(string(input), " ", "space", 10))
err = client.WriteMessage(websocket.TextMessage, input)
if err != nil {
log.Fatal("write:", err)
}
}
}
Used by 1
We read keys from stdin and send them to the server until we get EOF.
We specify xdotool if the key is not a QWERTY key or if KEYBOARD_ALWAYS_XDOTOOL is set to true.
reader := bufio.NewReader(os.Stdin)
for {
var key string
rune, _, err := reader.ReadRune() //:= fmt.Scan(&key)
key = addXDoToolIfNonQWERTY(string(rune))
if err != nil {
if err == io.EOF {
break
}
log.Fatal(err)
}
fmt.Println("send" + strings.Replace(key, " ", "space", 10))
err = client.WriteMessage(websocket.TextMessage, []byte(key))
if err != nil {
log.Fatal("write:", err)
}
}
Used by 1
package main
import (
"strings"
"io/ioutil"
"syscall"
"io"
"bufio"
"log"
"fmt"
"os"
@{gorilla/websocket import string}
)
func main(){@{handle client command}}