You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ORPA-pyOpenRPA/Resources/WPy64-3720/python-3.7.2.amd64/Lib/site-packages/mouse/__main__.py

27 lines
625 B

# -*- coding: utf-8 -*-
import mouse
import fileinput
import json
import sys
class_by_name = {
'ButtonEvent': mouse.ButtonEvent,
'WheelEvent': mouse.WheelEvent,
'MoveEvent': mouse.MoveEvent,
}
def print_event_json(event):
# Could use json.dumps(event.__dict__()), but this way we guarantee semantic order.
d = event._asdict()
d['event_class'] = event.__class__.__name__
print(json.dumps(d))
sys.stdout.flush()
mouse.hook(print_event_json)
def load(line):
d = json.loads(line)
class_ = class_by_name[d['event_class']]
del d['event_class']
return class_(**d)
mouse.play(load(line) for line in fileinput.input())