2023-01-30 01:45:00 +00:00
# Handle xdotool commands
Currently the two commands are `type` and `key` . `type` is used to type a character and `key` is used to type a special character like `Enter` or `Backspace` .
2023-03-13 18:24:02 +00:00
`type` is specified by '@{use xdotool cmd}', and `key` is specified by '@{use xdotool key cmd}'. If the command is not specified and `alwaysUseXdotool` is set from the environment variable, it will default to `type` .
2023-01-30 01:45:00 +00:00
``` go
--- handle xdotoool commands
2023-03-13 18:24:02 +00:00
if alwaysUseXdotool || strings.HasPrefix(message_string, "@{use xdotool cmd}") {
message_string = strings.TrimPrefix(message_string, "@{use xdotool cmd}")
2023-01-30 01:45:00 +00:00
if message_string == "" {
message_string = "\n"
}
if characterRegex.MatchString(message_string) {
for _, character := range message_string {
charString := string(character)
if charString == "\n" {
charString = "Enter"
} else if charString == "\t" {
charString = "Tab"
} else if charString == "\b" {
charString = "BackSpace"
} else{
doXDoTool("type", charString)
continue
}
// key is required for special characters
err = doXDoTool("key", charString)
continue
}
continue
} else {
doXDoTool("type", message_string)
}
continue
2023-03-13 18:24:02 +00:00
} else if strings.HasPrefix(message_string, "@{use xdotool key cmd}") {
message_string = strings.TrimPrefix(message_string, "@{use xdotool key cmd}")
2023-01-30 01:45:00 +00:00
if message_string == "" {
message_string = "\n"
}
doXDoTool("key", message_string)
continue
}
---
```