#200 Fix wheel macro timeout

xkb
sezanzeb 3 years ago
parent 1d79ad369b
commit 10700d8ece

@ -507,7 +507,7 @@ class Macro:
handler(EV_REL, code, value)
# scrolling moves much faster than mouse, so this
# waits between injections instead to make it slower
await asyncio.sleep(100 / resolved_speed)
await asyncio.sleep(1 / resolved_speed)
self.tasks.append(task)

@ -8,7 +8,7 @@ Examples for particular devices and/or use cases:
- Modifiers `Alt_L` `Control_L` `Control_R` `Shift_L` `Shift_R`
- Mouse buttons `BTN_LEFT` `BTN_RIGHT` `BTN_MIDDLE` `BTN_SIDE` ...
- Multimedia keys `KEY_NEXTSONG` `KEY_PLAYPAUSE` `XF86AudioMicMute` ...
- Mouse scroll `wheel(down, 1)` `wheel(up, 1)`
- Mouse scroll `wheel(down, 10)` `wheel(up, 10)`
- Mouse move `mouse(left, 1)` `mouse(right, 1)` `mouse(up, 1)` `mouse(down, 1)`
## Quick Overview of Macros

@ -125,8 +125,8 @@ Bear in mind that anti-cheat software might detect macros in games.
> Examples:
>
> ```c#
> mouse(up, 1)
> mouse(left, 2)
> mouse(up, 10)
> mouse(left, 20)
> ```
### event

@ -17,7 +17,7 @@
<text x="22.0" y="14">pylint</text>
</g>
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
<text x="63.0" y="15" fill="#010101" fill-opacity=".3">9.66</text>
<text x="62.0" y="14">9.66</text>
<text x="63.0" y="15" fill="#010101" fill-opacity=".3">9.62</text>
<text x="62.0" y="14">9.62</text>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

@ -28,23 +28,24 @@ from setuptools import setup
from setuptools.command.install import install
PO_FILES = 'po/*.po'
PO_FILES = "po/*.po"
class Install(install):
"""Add the commit hash and build .mo translations."""
def run(self):
try:
commit = os.popen('git rev-parse HEAD').read().strip()
if re.match(r'^([a-z]|[0-9])+$', commit):
commit = os.popen("git rev-parse HEAD").read().strip()
if re.match(r"^([a-z]|[0-9])+$", commit):
# for whatever reason different systems have different paths here
build_dir = ''
if os.path.exists('build/lib/keymapper'):
build_dir = 'build/lib/'
with open(f'{build_dir}keymapper/commit_hash.py', 'w+') as f:
build_dir = ""
if os.path.exists("build/lib/keymapper"):
build_dir = "build/lib/"
with open(f"{build_dir}keymapper/commit_hash.py", "w+") as f:
f.write(f"COMMIT_HASH = '{commit}'\n")
except Exception as e:
print('Failed to save the commit hash:', e)
print("Failed to save the commit hash:", e)
# generate .mo files
make_lang()
@ -52,21 +53,21 @@ class Install(install):
install.run(self)
def get_packages(base='keymapper'):
def get_packages(base="keymapper"):
"""Return all modules used in key-mapper.
For example 'keymapper.gui' or 'keymapper.injection.consumers'
"""
if not os.path.exists(os.path.join(base, '__init__.py')):
if not os.path.exists(os.path.join(base, "__init__.py")):
# only python modules
return []
result = [base.replace('/', '.')]
result = [base.replace("/", ".")]
for name in os.listdir(base):
if not os.path.isdir(os.path.join(base, name)):
continue
if name == '__pycache__':
if name == "__pycache__":
continue
# find more python submodules in that directory
@ -77,55 +78,57 @@ def get_packages(base='keymapper'):
def make_lang():
"""Build po files into mo/."""
os.makedirs('mo', exist_ok=True)
os.makedirs("mo", exist_ok=True)
for po_file in glob.glob(PO_FILES):
lang = splitext(basename(po_file))[0]
os.makedirs(join('mo', lang), exist_ok=True)
print(f'generating translation for {lang}')
subprocess.run(['msgfmt', '-o', join('mo', lang, 'key-mapper.mo'), str(po_file)], check=True)
os.makedirs(join("mo", lang), exist_ok=True)
print(f"generating translation for {lang}")
subprocess.run(
["msgfmt", "-o", join("mo", lang, "key-mapper.mo"), str(po_file)],
check=True,
)
lang_data = []
for po_file in glob.glob(PO_FILES):
lang = splitext(basename(po_file))[0]
lang_data.append((
f'/usr/share/key-mapper/lang/{lang}/LC_MESSAGES',
[f'mo/{lang}/key-mapper.mo']
))
lang_data.append(
(f"/usr/share/key-mapper/lang/{lang}/LC_MESSAGES", [f"mo/{lang}/key-mapper.mo"])
)
setup(
name='key-mapper',
version='1.2.1',
description='A tool to change the mapping of your input device buttons',
author='Sezanzeb',
author_email='proxima@sezanzeb.de',
url='https://github.com/sezanzeb/key-mapper',
license='GPL-3.0',
name="key-mapper",
version="1.2.1",
description="A tool to change the mapping of your input device buttons",
author="Sezanzeb",
author_email="proxima@sezanzeb.de",
url="https://github.com/sezanzeb/key-mapper",
license="GPL-3.0",
packages=get_packages(),
include_package_data=True,
data_files=[
# see development.md#files
*lang_data,
('/usr/share/key-mapper/', glob.glob('data/*')),
('/usr/share/applications/', ['data/key-mapper.desktop']),
('/usr/share/polkit-1/actions/', ['data/key-mapper.policy']),
('/usr/lib/systemd/system', ['data/key-mapper.service']),
('/etc/dbus-1/system.d/', ['data/keymapper.Control.conf']),
('/etc/xdg/autostart/', ['data/key-mapper-autoload.desktop']),
('/usr/lib/udev/rules.d', ['data/99-key-mapper.rules']),
('/usr/bin/', ['bin/key-mapper-gtk']),
('/usr/bin/', ['bin/key-mapper-service']),
('/usr/bin/', ['bin/key-mapper-control']),
('/usr/bin/', ['bin/key-mapper-helper']),
("/usr/share/key-mapper/", glob.glob("data/*")),
("/usr/share/applications/", ["data/key-mapper.desktop"]),
("/usr/share/polkit-1/actions/", ["data/key-mapper.policy"]),
("/usr/lib/systemd/system", ["data/key-mapper.service"]),
("/etc/dbus-1/system.d/", ["data/keymapper.Control.conf"]),
("/etc/xdg/autostart/", ["data/key-mapper-autoload.desktop"]),
("/usr/lib/udev/rules.d", ["data/99-key-mapper.rules"]),
("/usr/bin/", ["bin/key-mapper-gtk"]),
("/usr/bin/", ["bin/key-mapper-service"]),
("/usr/bin/", ["bin/key-mapper-control"]),
("/usr/bin/", ["bin/key-mapper-helper"]),
],
install_requires=[
'setuptools',
'evdev',
'pydbus',
'pygobject',
"setuptools",
"evdev",
"pydbus",
"pygobject",
],
cmdclass={
'install': Install,
"install": Install,
},
)

@ -748,10 +748,6 @@ class TestInjector(unittest.IsolatedAsyncioTestCase):
self.assertEqual(history.count((EV_KEY, code_d, 0)), 1)
def test_wheel(self):
# this tests both keycode_mapper and event_producer, and it seems
# to test stuff not covered in test_keycode_mapper, so it's a quite
# important one.
# wheel release events are made up with a debouncer
# map those two to stuff

@ -832,20 +832,28 @@ class TestMacros(MacroTestBase):
self.assertListEqual(self.result, expected)
async def test_mouse(self):
wheel_speed = 100
macro_1 = parse("mouse(up, 4)", self.context)
macro_2 = parse("wheel(left, 3)", self.context)
macro_2 = parse(f"wheel(left, {wheel_speed})", self.context)
macro_1.press_trigger()
macro_2.press_trigger()
asyncio.ensure_future(macro_1.run(self.handler))
asyncio.ensure_future(macro_2.run(self.handler))
await (asyncio.sleep(0.1))
sleep = 0.1
await (asyncio.sleep(sleep))
self.assertTrue(macro_1.is_holding())
self.assertTrue(macro_2.is_holding())
macro_1.release_trigger()
macro_2.release_trigger()
self.assertIn((EV_REL, REL_Y, -4), self.result)
self.assertIn((EV_REL, REL_HWHEEL, 1), self.result)
expected_wheel_event_count = sleep / (1 / wheel_speed)
actual_wheel_event_count = self.result.count((EV_REL, REL_HWHEEL, 1))
# this seems to have a tendency of injecting less wheel events,
# especially if the sleep is short
self.assertGreater(actual_wheel_event_count, expected_wheel_event_count * 0.8)
self.assertLess(actual_wheel_event_count, expected_wheel_event_count * 1.1)
self.assertIn(REL_WHEEL, macro_1.get_capabilities()[EV_REL])
self.assertIn(REL_Y, macro_1.get_capabilities()[EV_REL])

Loading…
Cancel
Save