ffctl/lib/marionette/cmd_actions.go

166 lines
3.0 KiB
Go

package marionette
import (
"time"
)
const (
KeyNull = '\ue000' + iota
KeyCancel
KeyHelp
KeyBackspace
KeyTab
KeyClear
KeyReturn
KeyEnter
KeyLeftShift
KeyLeftControl
KeyLeftAlt
KeyPause
KeyEscape
KeySpace
KeyPageUp
KeyPageDown
KeyEnd // 0xE010
KeyHome
KeyArrowLeft
KeyArrowUp
KeyArrowRight
KeyArrowDown
KeyInsert
KeyDelete
KeySemicolon
KeyEquals
KeyNumpad0
KeyNumpad1
KeyNumpad2
KeyNumpad3
KeyNumpad4
KeyNumpad5
KeyNumpad6 // 0xE020
KeyNumpad7
KeyNumpad8
KeyNumpad9
KeyNumpadMultiply
KeyNumpadAdd
KeyNumpadSeparator
KeyNumpadSubtract
KeyNumpadDecimal
KeyNumpadDivide
_KeyUnusedE02A
_KeyUnusedE02B
_KeyUnusedE02C
_KeyUnusedE02D
_KeyUnusedE02E
_KeyUnusedE02F
_KeyUnusedE030 // 0xE030
KeyF1
KeyF2
KeyF3
KeyF4
KeyF5
KeyF6
KeyF7
KeyF8
KeyF9
KeyF10
KeyF11
KeyF12
KeyLeftMeta
_KeyUnusedE03E
_KeyUnusedE03F
KeyZenkakuHankaku // 0xE040
_KeyUnusedE041
_KeyUnusedE042
_KeyUnusedE043
_KeyUnusedE044
_KeyUnusedE045
_KeyUnusedE046
_KeyUnusedE047
_KeyUnusedE048
_KeyUnusedE049
_KeyUnusedE04a
_KeyUnusedE04b
_KeyUnusedE04c
_KeyUnusedE04d
_KeyUnusedE04e
_KeyUnusedE04f
KeyRightShift // 0xE050
KeyRightControl
KeyRightAlt
KeyRightMeta
KeyNumpadPageUp
KeyNumpadPageDown
KeyNumpadEnd
KeyNumpadHome
KeyNumpadLeft
KeyNumpadUp
KeyNumpadRight
KeyNumpadDown
KeyNumpadInsert
KeyNumpadDelete
)
const (
MouseLeft = iota
MouseMiddle
MouseRight
)
type ActionsRequest struct {
Actions []ActionSequence `json:"actions"`
}
type ActionSource string
const (
ActionSourceNone ActionSource = "none"
ActionSourceKeyboard ActionSource = "key"
ActionSourceMouse ActionSource = "pointer"
)
type ActionSequence struct {
Type ActionSource `json:"type"`
ID string `json:"id"`
Actions []any `json:"actions"`
Parameters any `json:"parameters,omitempty"` // idk
}
func (t *TCPTransport) CmdPerformActions(actions ...ActionSequence) error {
_, err := DoCommand[struct {
Value Null `json:"value"`
}](t, "WebDriver:PerformActions", ActionsRequest{
Actions: actions,
})
return err
}
func (t *TCPTransport) CmdReleaseActions() error {
_, err := DoCommand[Null](t, "WebDriver:ReleaseActions", nil)
return err
}
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}
}