forked from llimllib/chrome-control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Input.py
187 lines (154 loc) · 9.37 KB
/
Input.py
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
from enum import Enum
from typing import Any, List
from base import ChromeCommand
class TouchPoint:
def __init__(self, state: str, x: int, y: int, radiusX: int=None, radiusY: int=None, rotationAngle: float=None, force: float=None, id: float=None):
# State of the touch point.
self.state = state
# X coordinate of the event relative to the main frame's viewport.
self.x = x
# Y coordinate of the event relative to the main frame's viewport. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
self.y = y
# X radius of the touch area (default: 1).
self.radiusX = radiusX
# Y radius of the touch area (default: 1).
self.radiusY = radiusY
# Rotation angle (default: 0.0).
self.rotationAngle = rotationAngle
# Force (default: 1.0).
self.force = force
# Identifier used to track touch sources between events, must be unique within an event.
self.id = id
GestureSourceType = Enum("GestureSourceType", "default touch mouse")
GestureSourceType.__doc__ = ""
class dispatchKeyEvent(ChromeCommand):
"""Dispatches a key event to the page."""
def __init__(self, type: str, modifiers: int=None, timestamp: float=None, text: str=None, unmodifiedText: str=None, keyIdentifier: str=None, code: str=None, key: str=None, windowsVirtualKeyCode: int=None, nativeVirtualKeyCode: int=None, autoRepeat: bool=None, isKeypad: bool=None, isSystemKey: bool=None):
# Type of the key event.
self.type = type
# Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
self.modifiers = modifiers
# Time at which the event occurred. Measured in UTC time in seconds since January 1, 1970 (default: current time).
self.timestamp = timestamp
# Text as generated by processing a virtual key code with a keyboard layout. Not needed for for <code>keyUp</code> and <code>rawKeyDown</code> events (default: "")
self.text = text
# Text that would have been generated by the keyboard if no modifiers were pressed (except for shift). Useful for shortcut (accelerator) key handling (default: "").
self.unmodifiedText = unmodifiedText
# Unique key identifier (e.g., 'U+0041') (default: "").
self.keyIdentifier = keyIdentifier
# Unique DOM defined string value for each physical key (e.g., 'KeyA') (default: "").
self.code = code
# Unique DOM defined string value describing the meaning of the key in the context of active modifiers, keyboard layout, etc (e.g., 'AltGr') (default: "").
self.key = key
# Windows virtual key code (default: 0).
self.windowsVirtualKeyCode = windowsVirtualKeyCode
# Native virtual key code (default: 0).
self.nativeVirtualKeyCode = nativeVirtualKeyCode
# Whether the event was generated from auto repeat (default: false).
self.autoRepeat = autoRepeat
# Whether the event was generated from the keypad (default: false).
self.isKeypad = isKeypad
# Whether the event was a system key event (default: false).
self.isSystemKey = isSystemKey
class dispatchMouseEvent(ChromeCommand):
"""Dispatches a mouse event to the page."""
def __init__(self, type: str, x: int, y: int, modifiers: int=None, timestamp: float=None, button: str=None, clickCount: int=None):
# Type of the mouse event.
self.type = type
# X coordinate of the event relative to the main frame's viewport.
self.x = x
# Y coordinate of the event relative to the main frame's viewport. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
self.y = y
# Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
self.modifiers = modifiers
# Time at which the event occurred. Measured in UTC time in seconds since January 1, 1970 (default: current time).
self.timestamp = timestamp
# Mouse button (default: "none").
self.button = button
# Number of times the mouse button was clicked (default: 0).
self.clickCount = clickCount
class dispatchTouchEvent(ChromeCommand):
"""Dispatches a touch event to the page."""
def __init__(self, type: str, touchPoints: List, modifiers: int=None, timestamp: float=None):
# Type of the touch event.
self.type = type
# Touch points.
self.touchPoints = touchPoints
# Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
self.modifiers = modifiers
# Time at which the event occurred. Measured in UTC time in seconds since January 1, 1970 (default: current time).
self.timestamp = timestamp
class emulateTouchFromMouseEvent(ChromeCommand):
"""Emulates touch event from the mouse event parameters."""
def __init__(self, type: str, x: int, y: int, timestamp: float, button: str, deltaX: float=None, deltaY: float=None, modifiers: int=None, clickCount: int=None):
# Type of the mouse event.
self.type = type
# X coordinate of the mouse pointer in DIP.
self.x = x
# Y coordinate of the mouse pointer in DIP.
self.y = y
# Time at which the event occurred. Measured in UTC time in seconds since January 1, 1970.
self.timestamp = timestamp
# Mouse button.
self.button = button
# X delta in DIP for mouse wheel event (default: 0).
self.deltaX = deltaX
# Y delta in DIP for mouse wheel event (default: 0).
self.deltaY = deltaY
# Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
self.modifiers = modifiers
# Number of times the mouse button was clicked (default: 0).
self.clickCount = clickCount
class synthesizePinchGesture(ChromeCommand):
"""Synthesizes a pinch gesture over a time period by issuing appropriate touch events."""
def __init__(self, x: int, y: int, scaleFactor: float, relativeSpeed: int=None, gestureSourceType: "GestureSourceType"=None):
# X coordinate of the start of the gesture in CSS pixels.
self.x = x
# Y coordinate of the start of the gesture in CSS pixels.
self.y = y
# Relative scale factor after zooming (>1.0 zooms in, <1.0 zooms out).
self.scaleFactor = scaleFactor
# Relative pointer speed in pixels per second (default: 800).
self.relativeSpeed = relativeSpeed
# Which type of input events to be generated (default: 'default', which queries the platform for the preferred input type).
self.gestureSourceType = gestureSourceType
class synthesizeScrollGesture(ChromeCommand):
"""Synthesizes a scroll gesture over a time period by issuing appropriate touch events."""
def __init__(self, x: int, y: int, xDistance: int=None, yDistance: int=None, xOverscroll: int=None, yOverscroll: int=None, preventFling: bool=None, speed: int=None, gestureSourceType: "GestureSourceType"=None, repeatCount: int=None, repeatDelayMs: int=None, interactionMarkerName: str=None):
# X coordinate of the start of the gesture in CSS pixels.
self.x = x
# Y coordinate of the start of the gesture in CSS pixels.
self.y = y
# The distance to scroll along the X axis (positive to scroll left).
self.xDistance = xDistance
# The distance to scroll along the Y axis (positive to scroll up).
self.yDistance = yDistance
# The number of additional pixels to scroll back along the X axis, in addition to the given distance.
self.xOverscroll = xOverscroll
# The number of additional pixels to scroll back along the Y axis, in addition to the given distance.
self.yOverscroll = yOverscroll
# Prevent fling (default: true).
self.preventFling = preventFling
# Swipe speed in pixels per second (default: 800).
self.speed = speed
# Which type of input events to be generated (default: 'default', which queries the platform for the preferred input type).
self.gestureSourceType = gestureSourceType
# The number of times to repeat the gesture (default: 0).
self.repeatCount = repeatCount
# The number of milliseconds delay between each repeat. (default: 250).
self.repeatDelayMs = repeatDelayMs
# The name of the interaction markers to generate, if not empty (default: "").
self.interactionMarkerName = interactionMarkerName
class synthesizeTapGesture(ChromeCommand):
"""Synthesizes a tap gesture over a time period by issuing appropriate touch events."""
def __init__(self, x: int, y: int, duration: int=None, tapCount: int=None, gestureSourceType: "GestureSourceType"=None):
# X coordinate of the start of the gesture in CSS pixels.
self.x = x
# Y coordinate of the start of the gesture in CSS pixels.
self.y = y
# Duration between touchdown and touchup events in ms (default: 50).
self.duration = duration
# Number of times to perform the tap (e.g. 2 for double tap, default: 1).
self.tapCount = tapCount
# Which type of input events to be generated (default: 'default', which queries the platform for the preferred input type).
self.gestureSourceType = gestureSourceType