forked from playwright-community/playwright-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.go
109 lines (92 loc) · 2.32 KB
/
input.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package playwright
type mouseImpl struct {
channel *channel
}
func newMouse(channel *channel) *mouseImpl {
return &mouseImpl{
channel: channel,
}
}
func (m *mouseImpl) Move(x float64, y float64, options ...MouseMoveOptions) error {
_, err := m.channel.Send("mouseMove", map[string]interface{}{
"x": x,
"y": y,
}, options)
return err
}
func (m *mouseImpl) Down(options ...MouseDownOptions) error {
_, err := m.channel.Send("mouseDown", options)
return err
}
func (m *mouseImpl) Up(options ...MouseUpOptions) error {
_, err := m.channel.Send("mouseUp", options)
return err
}
func (m *mouseImpl) Click(x, y float64, options ...MouseClickOptions) error {
_, err := m.channel.Send("mouseClick", map[string]interface{}{
"x": x,
"y": y,
}, options)
return err
}
func (m *mouseImpl) Dblclick(x, y float64, options ...MouseDblclickOptions) error {
var option MouseDblclickOptions
if len(options) == 1 {
option = options[0]
}
return m.Click(x, y, MouseClickOptions{
ClickCount: Int(2),
Button: option.Button,
Delay: option.Delay,
})
}
type keyboardImpl struct {
channel *channel
}
func newKeyboard(channel *channel) *keyboardImpl {
return &keyboardImpl{
channel: channel,
}
}
func (m *keyboardImpl) Down(key string) error {
_, err := m.channel.Send("keyboardDown", map[string]interface{}{
"key": key,
})
return err
}
func (m *keyboardImpl) Up(key string) error {
_, err := m.channel.Send("keyboardUp", map[string]interface{}{
"key": key,
})
return err
}
func (m *keyboardImpl) InsertText(text string) error {
_, err := m.channel.Send("keyboardInsertText", map[string]interface{}{
"text": text,
})
return err
}
func (m *keyboardImpl) Type(text string, options ...KeyboardTypeOptions) error {
_, err := m.channel.Send("keyboardInsertText", map[string]interface{}{
"text": text,
}, options)
return err
}
func (m *keyboardImpl) Press(key string, options ...KeyboardPressOptions) error {
_, err := m.channel.Send("keyboardPress", map[string]interface{}{
"key": key,
}, options)
return err
}
type touchscreenImpl struct {
channel *channel
}
func newTouchscreen(channel *channel) *touchscreenImpl {
return &touchscreenImpl{
channel: channel,
}
}
func (t *touchscreenImpl) Tap(x int, y int) error {
_, err := t.channel.Send("touchscreenTap", map[string]interface{}{"x": x, "y": y})
return err
}