Comments (7)
You can sort them together using lambda i: i.time
as key, or just append both to the same list. But that's not very useful because you still need to split them later to replay.
Thats something still missing from the libraries, but I intent to fix in the future. You can still replay them in separate threads.
from mouse.
class Recorder(object):
def __init__(self):
self.mouse_recorded=[]
self.keyboard_recorded=[]
def record(self,key_abort_seq='esc, esc'):
self.mouse_recorded[:] = [] # reset upon new recording
self.keyboard_recorded[:] = []
mouse.hook(self.mouse_recorded.append)
keyboard.hook(self.keyboard_recorded.append)
keyboard.wait(key_abort_seq)
mouse.unhook(self.mouse_recorded.append)
keyboard.unhook(self.keyboard_recorded.append)
def playmouse(self,**kwds):
'''
play only mouse events
'''
mouse.play(self.mouse_recorded,**kwds)
def playkeyboard(self,**kwds):
'''
play only keyboard events
'''
keyboard.play(self.mouse_recorded,**kwds)
def play(self,key_speed_factor=1.0, mouse_speed_factor=1.0, **kwds):
'''
play both mouse and keyboard events in order
'''
k=sorted(self.mouse_recorded+ self.keyboard_recorded,key=lambda i:i.time)
for c,m in it.groupby(k,key=lambda i:isinstance(i,keyboard.KeyboardEvent)):
if c:
speed_factor = kwds.pop('speed_factor',key_speed_factor)
keyboard.play(m,speed_factor=speed_factor,**kwds)
else:
speed_factor = kwds.pop('speed_factor',mouse_speed_factor)
mouse.play(m,speed_factor=speed_factor,**kwds)
Then, you can do
r = Recorder()
r.record()
Thanks for the headstart!
from mouse.
Not with the record
function, but record
is so simple that you can just reimplement it:
Line 226 in f369010
My suggestion:
import mouse, keyboard
recorded = []
mouse.hook(recorded.append)
keyboard.wait('esc, esc')
mouse.unhook(recorded.append)
print(recorded)
from mouse.
If this solves your problem, I'll add to the examples directory.
from mouse.
It does! Thanks!
Along these lines, is it possible to simultaneously record both mouse and keyboard interactions? I have tried the following:
mouse_recorded = []
keyboard_recorded = []
mouse.hook(mouse_recorded.append)
keyboard.hook(keyboard_recorded.append)
keyboard.wait('esc, esc')
mouse.unhook(mouse_recorded.append)
keyboard.unhook(keyboard_recorded.append)
print(mouse_recorded)
print keyboard_recorded
However there is no time-alignment between the two lists, so I don't know the sequential order of the mouse and keyboard interactions.
Any ideas here?
from mouse.
Thanks @reckoner for the script. To simplify this process in the future, I'll add an event.replay(speed_factor)
method to both keyboard and mouse events. This would allow a simple for event in events: event.replay()
. Unfortunately it requires merging the events into the main file for each module to avoid circular dependencies, which breaks compatibility or requires hackish aliases, so I'll wait until the next breaking changeset.
from mouse.
When I call
r = Recorder()
r.record()
I get this error:
File "keyboard/__init__.py", line 465, in hook
_hooks[callback] = _hooks[remove_] = remove_
TypeError: unhashable type: 'list'
from mouse.
Related Issues (20)
- mouse.move doesnt accept a list HOT 2
- Docker support
- Is there a way to detect either up or down mouse wheel scrolling?
- mouse.click() doesn't work on Ubuntu 22.04.1 LTS HOT 2
- not DPI aware HOT 3
- Touchscreen support - Question
- get_position altered after importing pyautogui
- typing this library
- Will creating multiple concurrent browsers automation also create individual mouse instances for each of the browsers?
- side mouse buttons plz help!!!
- [WAYLAND] Mouse won't move HOT 2
- [feature-request] Docs
- [BUG] `ImportError` while installing the (pre-release) package on macOS HOT 1
- release() in thread
- I have a question. And suggestion.
- System freezes after mouse.play()
- The mouse.DOWN type hook does not work correctly.
- ModuleNotFoundError: No module named 'mouse' HOT 2
- OSError: Unsupported platform 'Darwin'
- [Feature request] Add suppress parameter to the hook function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mouse.