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