2024-02-09 01:53:56 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2024-02-09 08:05:39 +00:00
|
|
|
"log"
|
2024-02-09 01:53:56 +00:00
|
|
|
"os"
|
2024-02-09 08:05:39 +00:00
|
|
|
"time"
|
2024-02-09 01:53:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if err := WithSession(context.Background(), func(ctx context.Context, t *TCPTransport) error {
|
|
|
|
// TODO
|
2024-02-09 08:05:39 +00:00
|
|
|
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)
|
2024-02-09 01:53:56 +00:00
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
2024-02-09 08:05:39 +00:00
|
|
|
|
|
|
|
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}
|
|
|
|
}
|