diff --git a/keymapper/injection/macros/macro.py b/keymapper/injection/macros/macro.py
index 15093d74..56dc0fc7 100644
--- a/keymapper/injection/macros/macro.py
+++ b/keymapper/injection/macros/macro.py
@@ -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)
diff --git a/readme/examples.md b/readme/examples.md
index 5faa2340..00ba7656 100644
--- a/readme/examples.md
+++ b/readme/examples.md
@@ -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
diff --git a/readme/macros.md b/readme/macros.md
index 2886ab0a..68566ab1 100644
--- a/readme/macros.md
+++ b/readme/macros.md
@@ -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
diff --git a/readme/pylint.svg b/readme/pylint.svg
index 280836f4..df7ede91 100644
--- a/readme/pylint.svg
+++ b/readme/pylint.svg
@@ -17,7 +17,7 @@
pylint
- 9.66
- 9.66
+ 9.62
+ 9.62
\ No newline at end of file
diff --git a/setup.py b/setup.py
index c780353e..7b4e351a 100644
--- a/setup.py
+++ b/setup.py
@@ -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,
},
)
diff --git a/tests/testcases/test_injector.py b/tests/testcases/test_injector.py
index 965433e7..d05cd5c9 100644
--- a/tests/testcases/test_injector.py
+++ b/tests/testcases/test_injector.py
@@ -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
diff --git a/tests/testcases/test_macros.py b/tests/testcases/test_macros.py
index e7b05406..8c9daa16 100644
--- a/tests/testcases/test_macros.py
+++ b/tests/testcases/test_macros.py
@@ -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])