mirror of
https://github.com/sezanzeb/input-remapper
synced 2024-11-04 12:00:16 +00:00
random w, improved parsing debug output
This commit is contained in:
parent
e74c91e1f6
commit
98811a3358
@ -103,8 +103,12 @@ class _Macro:
|
|||||||
|
|
||||||
def wait(self, min, max=None):
|
def wait(self, min, max=None):
|
||||||
"""Wait a random time in milliseconds"""
|
"""Wait a random time in milliseconds"""
|
||||||
# TODO random
|
if max is None:
|
||||||
self.tasks.append(lambda: time.sleep(min / 1000))
|
sleeptime = min
|
||||||
|
else:
|
||||||
|
sleeptime = random.random() * (max - min) + min
|
||||||
|
|
||||||
|
self.tasks.append(lambda: time.sleep(sleeptime / 1000))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
@ -169,7 +173,6 @@ def _parse_recurse(macro, handler, macro_instance=None, depth=0):
|
|||||||
assert isinstance(macro_instance, _Macro)
|
assert isinstance(macro_instance, _Macro)
|
||||||
|
|
||||||
macro = macro.strip()
|
macro = macro.strip()
|
||||||
logger.spam('%sinput %s', ' ' * depth, macro)
|
|
||||||
space = ' ' * depth
|
space = ' ' * depth
|
||||||
|
|
||||||
# is it another macro?
|
# is it another macro?
|
||||||
@ -254,6 +257,7 @@ def parse(macro, handler):
|
|||||||
macro will write to this function once executed with `.run()`.
|
macro will write to this function once executed with `.run()`.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
logger.spam('input %s', macro)
|
||||||
return _parse_recurse(macro, handler)
|
return _parse_recurse(macro, handler)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Failed to parse macro "%s": %s', macro, e)
|
logger.error('Failed to parse macro "%s": %s', macro, e)
|
||||||
|
@ -51,7 +51,7 @@ class TestMacros(unittest.TestCase):
|
|||||||
])
|
])
|
||||||
|
|
||||||
def test_3(self):
|
def test_3(self):
|
||||||
parse('r(3, k(m).w(200))', self.handler).run()
|
parse('r(3, k(m).w(200, 400))', self.handler).run()
|
||||||
# TODO test passed time
|
# TODO test passed time
|
||||||
self.assertListEqual(self.result, [
|
self.assertListEqual(self.result, [
|
||||||
('m', 1), ('m', 0),
|
('m', 1), ('m', 0),
|
||||||
|
Loading…
Reference in New Issue
Block a user