ffctl/ffscript/main.go

81 lines
1.8 KiB
Go

package main
import (
"context"
"fmt"
"log"
"os"
"time"
)
func main() {
if err := WithSession(context.Background(), func(ctx context.Context, t *TCPTransport) error {
// TODO
resp, err := DoCommand[any](t, "WebDriver:PerformActions", map[string]any{
"actions": []any{
map[string]any{
"type": "key",
"id": "???",
"actions": []any{
ActionKeyDown(KeyF12),
ActionKeyUp(KeyF12),
ActionPause(10 * time.Second),
},
//"parameters": idk,
},
},
})
if err != nil {
return err
}
log.Printf("resp=%#v", resp)
resp, err = DoCommand[any](t, "WebDriver:ReleaseActions", nil)
if err != nil {
return err
}
log.Printf("resp=%#v", resp)
return nil
}); err != nil {
fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
os.Exit(1)
}
}
type ActionSequence struct {
Type string `json:"type"` // "key"
ID string `json:"id"`
Actions []any `json:"actions"`
}
// actions:
const (
MouseLeft = iota
MouseMiddle
MouseRight
)
func ActionKeyDown(key rune) any {
return map[string]any{"type": "keyDown", "value": string([]rune{key})}
}
func ActionKeyUp(key rune) any {
return map[string]any{"type": "keyUp", "value": string([]rune{key})}
}
func ActionPause(dur time.Duration) any {
return map[string]any{"type": "pause", "duration": dur.Milliseconds()}
}
func ActionPointerMove(x, y int64) any {
// nb: more optional args
return map[string]any{"type": "pointerMove", "x": x, "y": y}
}
func ActionPointerDown(button uint8) any {
return map[string]any{"type": "pointerDown", "button": button}
}
func ActionPointerUp(button uint8) any {
return map[string]any{"type": "pointerUp", "button": button}
}
func ActionScroll(x, y, deltaX, deltaY int64) any {
// nb: more optional args
return map[string]any{"type": "scroll", "x": x, "y": y, "deltaX": deltaX, "deltaY": deltaY}
}