-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfingers.py
86 lines (61 loc) · 2.64 KB
/
fingers.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
# This file is part of ClIDE
# ClIDE - A live-modifiable command-line IDE that can accept commands as pseudocode
# @author Andrew Phillips
# @copyright 2017 Andrew Phillips <skeledrew@gmail.com>
# ClIDE is free software; you can redistribute it and/or
# modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
# License as published by the Free Software Foundation; either
# version 3 of the License, or any later version.
# ClIDE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU AFFERO GENERAL PUBLIC LICENSE for more details.
# You should have received a copy of the GNU Affero General Public
# License along with ClIDE. If not, see <http://www.gnu.org/licenses/>.
'''
'''
from pynput.mouse import Button, Controller as MouseControl
from pynput.keyboard import Key, Controller as KbdControl
class Finger():
def __init__(self, speed=10):
self._mse = MouseControl()
self._kbd = KbdControl()
self._speed = speed
def type(self, keys):
self._kbd.type(keys)
def move(self, dx, dy, type_='abs'):
if type_ == 'abs':
self._mse.position = (dx, dy)
else:
self._mse.move(dx, dy)
def click(self, button='left', count=1):
button = getattr(Button, button, 'left')
self._mse.click(button, count)
def scroll(self, vscr=2, hscr=0):
self._mse.scroll(hscr, vscr)
def drag(self, to=(), frm=(), button='left'):
# simulate a drag. TODO: make in increments instead of instant
if not frm: frm = self._mse.position
if not to: to = self._mse.position
button = getattr(Button, button, 'left')
self._mse.press(button)
self._mse.position = to
self._mse.release(button)
#while not self._mse.position == to:
# simulate movement one step at a time
#x_pos = self._mse.position[0]
#y_pos = self._mse.position[1]
#if not x_pos == to[0]: x_pos
def press(self, device='mouse', button='left'):
if device == 'mouse':
self._mse.press(getattr(Button, button, 'left'))
else:
key = button if len(button) == 1 else getattr(Key, button, 'space')
self._kbd.press(key)
def release(self, device='mouse', button='left'):
# specify mouse or keyboard
if device == 'mouse':
self._mse.release(getattr(Button, button, 'left'))
else:
key = button if len(button) == 1 else getattr(Key, button, 'space')
self._kbd.release(key)