chore(repo): baseline du fork input-remapper (upstream v2.2.1)
Le dépôt ne contenait que README.md ; ajout de l'intégralité du code fonctionnel du fork comme socle stable de la branche de release. L'état runtime d'orchestration (.ideai/) est exclu du suivi. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
0
inputremapper/injection/macros/tasks/__init__.py
Normal file
0
inputremapper/injection/macros/tasks/__init__.py
Normal file
72
inputremapper/injection/macros/tasks/add.py
Normal file
72
inputremapper/injection/macros/tasks/add.py
Normal file
@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from inputremapper.configs.validation_errors import MacroError
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.task import Task
|
||||
from inputremapper.logging.logger import logger
|
||||
|
||||
|
||||
class AddTask(Task):
|
||||
"""Add a number to a variable."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="variable",
|
||||
position=0,
|
||||
types=[int, float, None],
|
||||
is_variable_name=True,
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="value",
|
||||
position=1,
|
||||
types=[int, float],
|
||||
),
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
argument = self.get_argument("variable")
|
||||
try:
|
||||
current = argument.get_value()
|
||||
except MacroError:
|
||||
return
|
||||
|
||||
if current is None:
|
||||
logger.debug(
|
||||
'"%s" initialized with 0',
|
||||
self.arguments["variable"].get_variable_name(),
|
||||
)
|
||||
argument.set_value(0)
|
||||
current = 0
|
||||
|
||||
addend = self.get_argument("value").get_value()
|
||||
|
||||
if not isinstance(current, (int, float)):
|
||||
logger.error(
|
||||
'Expected variable "%s" to contain a number, but got "%s"',
|
||||
argument.get_value(),
|
||||
current,
|
||||
)
|
||||
return
|
||||
|
||||
logger.debug("%s += %s", current, addend)
|
||||
argument.set_value(current + addend)
|
||||
64
inputremapper/injection/macros/tasks/event.py
Normal file
64
inputremapper/injection/macros/tasks/event.py
Normal file
@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from evdev.ecodes import ecodes
|
||||
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.task import Task
|
||||
|
||||
|
||||
class EventTask(Task):
|
||||
"""Write any event.
|
||||
|
||||
For example event(EV_KEY, KEY_A, 1)
|
||||
"""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="type",
|
||||
position=0,
|
||||
types=[str, int],
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="code",
|
||||
position=1,
|
||||
types=[str, int],
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="value",
|
||||
position=2,
|
||||
types=[int],
|
||||
),
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
type_ = self.get_argument("type").get_value()
|
||||
code = self.get_argument("code").get_value()
|
||||
value = self.get_argument("value").get_value()
|
||||
|
||||
if isinstance(type_, str):
|
||||
type_ = ecodes[type_.upper()]
|
||||
if isinstance(code, str):
|
||||
code = ecodes[code.upper()]
|
||||
|
||||
callback(type_, code, value)
|
||||
await self.keycode_pause()
|
||||
71
inputremapper/injection/macros/tasks/hold.py
Normal file
71
inputremapper/injection/macros/tasks/hold.py
Normal file
@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
from evdev.ecodes import EV_KEY
|
||||
|
||||
from inputremapper.configs.keyboard_layout import keyboard_layout
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.macro import Macro
|
||||
from inputremapper.injection.macros.task import Task
|
||||
|
||||
|
||||
class HoldTask(Task):
|
||||
"""Loop the macro until the trigger-key is released."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="macro",
|
||||
position=0,
|
||||
types=[Macro, str, None],
|
||||
)
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
macro = self.get_argument("macro").get_value()
|
||||
|
||||
if macro is None:
|
||||
await self._trigger_release_event.wait()
|
||||
return
|
||||
|
||||
if isinstance(macro, str):
|
||||
# if macro is a key name, hold down the key while the
|
||||
# keyboard key is physically held down
|
||||
symbol = macro
|
||||
self.get_argument("macro").assert_is_symbol(symbol)
|
||||
|
||||
code = keyboard_layout.get(symbol)
|
||||
callback(EV_KEY, code, 1)
|
||||
await self._trigger_release_event.wait()
|
||||
callback(EV_KEY, code, 0)
|
||||
|
||||
if isinstance(macro, Macro):
|
||||
# repeat the macro forever while the key is held down
|
||||
while self.is_holding():
|
||||
# run the child macro completely to avoid
|
||||
# not-releasing any key
|
||||
await macro.run(callback)
|
||||
# prevent input-remapper from freezing up and making the system hard
|
||||
# to control, by adding 1ms of asyncio.sleep during which the event
|
||||
# loop can do other things
|
||||
await asyncio.sleep(1 / 1000)
|
||||
55
inputremapper/injection/macros/tasks/hold_keys.py
Normal file
55
inputremapper/injection/macros/tasks/hold_keys.py
Normal file
@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from evdev.ecodes import EV_KEY
|
||||
|
||||
from inputremapper.configs.keyboard_layout import keyboard_layout
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig, ArgumentFlags
|
||||
from inputremapper.injection.macros.task import Task
|
||||
|
||||
|
||||
class HoldKeysTask(Task):
|
||||
"""Hold down multiple keys, equivalent to `a + b + c + ...`."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="*symbols",
|
||||
position=ArgumentFlags.spread,
|
||||
types=[str],
|
||||
is_symbol=True,
|
||||
)
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
symbols = self.get_argument("*symbols").get_values()
|
||||
|
||||
codes = [keyboard_layout.get(symbol) for symbol in symbols]
|
||||
|
||||
for code in codes:
|
||||
callback(EV_KEY, code, 1)
|
||||
await self.keycode_pause()
|
||||
|
||||
await self._trigger_release_event.wait()
|
||||
|
||||
for code in codes[::-1]:
|
||||
callback(EV_KEY, code, 0)
|
||||
await self.keycode_pause()
|
||||
66
inputremapper/injection/macros/tasks/if_eq.py
Normal file
66
inputremapper/injection/macros/tasks/if_eq.py
Normal file
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.macro import Macro
|
||||
from inputremapper.injection.macros.task import Task
|
||||
|
||||
|
||||
class IfEqTask(Task):
|
||||
"""Compare two values."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="value_1",
|
||||
position=0,
|
||||
types=[str, int, float],
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="value_2",
|
||||
position=1,
|
||||
types=[str, int, float],
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="then",
|
||||
position=2,
|
||||
types=[Macro, None],
|
||||
default=None,
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="else",
|
||||
position=3,
|
||||
types=[Macro, None],
|
||||
default=None,
|
||||
),
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
value_1 = self.get_argument("value_1").get_value()
|
||||
value_2 = self.get_argument("value_2").get_value()
|
||||
then = self.get_argument("then").get_value()
|
||||
else_ = self.get_argument("else").get_value()
|
||||
|
||||
if value_1 == value_2:
|
||||
if then is not None:
|
||||
await then.run(callback)
|
||||
elif else_ is not None:
|
||||
await else_.run(callback)
|
||||
71
inputremapper/injection/macros/tasks/if_led.py
Normal file
71
inputremapper/injection/macros/tasks/if_led.py
Normal file
@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from evdev.ecodes import (
|
||||
LED_NUML,
|
||||
LED_CAPSL,
|
||||
)
|
||||
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.macro import Macro
|
||||
from inputremapper.injection.macros.task import Task
|
||||
|
||||
|
||||
class IfLedTask(Task):
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="then",
|
||||
position=0,
|
||||
types=[Macro, None],
|
||||
default=None,
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="else",
|
||||
position=1,
|
||||
types=[Macro, None],
|
||||
default=None,
|
||||
),
|
||||
]
|
||||
|
||||
led_code = None
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
then = self.get_argument("then").get_value()
|
||||
else_ = self.get_argument("else").get_value()
|
||||
|
||||
# self.context is only None when the frontend is parsing the macro
|
||||
assert self.context is not None
|
||||
led_on = self.led_code in self.context.get_leds()
|
||||
|
||||
if led_on:
|
||||
if then is not None:
|
||||
await then.run(callback)
|
||||
elif else_ is not None:
|
||||
await else_.run(callback)
|
||||
|
||||
|
||||
class IfNumlockTask(IfLedTask):
|
||||
led_code = LED_NUML
|
||||
|
||||
|
||||
class IfCapslockTask(IfLedTask):
|
||||
led_code = LED_CAPSL
|
||||
96
inputremapper/injection/macros/tasks/if_single.py
Normal file
96
inputremapper/injection/macros/tasks/if_single.py
Normal file
@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
from evdev.ecodes import EV_KEY
|
||||
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.macro import Macro
|
||||
from inputremapper.injection.macros.task import Task
|
||||
from inputremapper.input_event import InputEvent
|
||||
|
||||
|
||||
class IfSingleTask(Task):
|
||||
"""If a key was pressed without combining it."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="then",
|
||||
position=0,
|
||||
types=[Macro, None],
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="else",
|
||||
position=1,
|
||||
types=[Macro, None],
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="timeout",
|
||||
position=2,
|
||||
types=[int, float, None],
|
||||
default=None,
|
||||
),
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
assert self.context is not None
|
||||
another_key_pressed_event = asyncio.Event()
|
||||
then = self.get_argument("then").get_value()
|
||||
else_ = self.get_argument("else").get_value()
|
||||
|
||||
async def listener(event: InputEvent) -> None:
|
||||
if event.type != EV_KEY:
|
||||
# Ignore anything that is not a key
|
||||
return
|
||||
|
||||
if event.is_pressed():
|
||||
# Another key was pressed
|
||||
another_key_pressed_event.set()
|
||||
return
|
||||
|
||||
self.add_event_listener(listener)
|
||||
|
||||
timeout = self.get_argument("timeout").get_value()
|
||||
|
||||
# Wait for anything of importance to happen, that would determine the
|
||||
# outcome of the if_single macro.
|
||||
await asyncio.wait(
|
||||
[
|
||||
asyncio.Task(another_key_pressed_event.wait()),
|
||||
asyncio.Task(self._trigger_release_event.wait()),
|
||||
],
|
||||
timeout=timeout / 1000 if timeout else None,
|
||||
return_when=asyncio.FIRST_COMPLETED,
|
||||
)
|
||||
|
||||
self.remove_event_listener(listener)
|
||||
|
||||
if not self.is_holding():
|
||||
if then:
|
||||
await then.run(callback)
|
||||
else:
|
||||
# If the trigger has not been released, then `await asyncio.wait` above
|
||||
# could only have finished waiting due to a timeout, or because another
|
||||
# key was pressed.
|
||||
if else_:
|
||||
await else_.run(callback)
|
||||
79
inputremapper/injection/macros/tasks/if_tap.py
Normal file
79
inputremapper/injection/macros/tasks/if_tap.py
Normal file
@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.macro import Macro
|
||||
from inputremapper.injection.macros.task import Task
|
||||
|
||||
|
||||
class IfTapTask(Task):
|
||||
"""If a key was pressed quickly.
|
||||
|
||||
macro key pressed -> if_tap starts -> key released -> then
|
||||
|
||||
macro key pressed -> released (does other stuff in the meantime)
|
||||
-> if_tap starts -> pressed -> released -> then
|
||||
"""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="then",
|
||||
position=0,
|
||||
types=[Macro, None],
|
||||
default=None,
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="else",
|
||||
position=1,
|
||||
types=[Macro, None],
|
||||
default=None,
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="timeout",
|
||||
position=2,
|
||||
types=[int, float],
|
||||
default=300,
|
||||
),
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
then = self.get_argument("then").get_value()
|
||||
else_ = self.get_argument("else").get_value()
|
||||
timeout = self.get_argument("timeout").get_value() / 1000
|
||||
|
||||
try:
|
||||
await asyncio.wait_for(self._wait(), timeout)
|
||||
if then:
|
||||
await then.run(callback)
|
||||
except asyncio.TimeoutError:
|
||||
if else_:
|
||||
await else_.run(callback)
|
||||
|
||||
async def _wait(self):
|
||||
"""Wait for a release, or if nothing pressed yet, a press and release."""
|
||||
if self.is_holding():
|
||||
await self._trigger_release_event.wait()
|
||||
else:
|
||||
await self._trigger_press_event.wait()
|
||||
await self._trigger_release_event.wait()
|
||||
72
inputremapper/injection/macros/tasks/ifeq.py
Normal file
72
inputremapper/injection/macros/tasks/ifeq.py
Normal file
@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.macro import Macro
|
||||
from inputremapper.injection.macros.task import Task
|
||||
|
||||
|
||||
class DeprecatedIfEqTask(Task):
|
||||
"""Old version of if_eq, kept for compatibility reasons.
|
||||
|
||||
This can't support a comparison like ifeq("foo", $blub) with blub containing
|
||||
"foo" without breaking old functionality, because "foo" is treated as a
|
||||
variable name.
|
||||
"""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="variable",
|
||||
position=0,
|
||||
types=[str, float, int, None],
|
||||
is_variable_name=True,
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="value",
|
||||
position=1,
|
||||
types=[str, float, int, None],
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="then",
|
||||
position=2,
|
||||
types=[Macro, None],
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="else",
|
||||
position=3,
|
||||
types=[Macro, None],
|
||||
),
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
actual_value = self.get_argument("variable").get_value()
|
||||
value = self.get_argument("value").get_value()
|
||||
then = self.get_argument("then").get_value()
|
||||
else_ = self.get_argument("else").get_value()
|
||||
|
||||
# The old ifeq function became somewhat incompatible with the new macro code.
|
||||
# I need to compare them as strings to keep this working.
|
||||
if str(actual_value) == str(value):
|
||||
if then is not None:
|
||||
await then.run(callback)
|
||||
elif else_ is not None:
|
||||
await else_.run(callback)
|
||||
49
inputremapper/injection/macros/tasks/key.py
Normal file
49
inputremapper/injection/macros/tasks/key.py
Normal file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from evdev.ecodes import EV_KEY
|
||||
|
||||
from inputremapper.configs.keyboard_layout import keyboard_layout
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.task import Task
|
||||
|
||||
|
||||
class KeyTask(Task):
|
||||
"""Write the symbol."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="symbol",
|
||||
position=0,
|
||||
types=[str],
|
||||
is_symbol=True,
|
||||
)
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
symbol = self.get_argument("symbol").get_value()
|
||||
code = keyboard_layout.get(symbol)
|
||||
|
||||
callback(EV_KEY, code, 1)
|
||||
await self.keycode_pause()
|
||||
callback(EV_KEY, code, 0)
|
||||
await self.keycode_pause()
|
||||
45
inputremapper/injection/macros/tasks/key_down.py
Normal file
45
inputremapper/injection/macros/tasks/key_down.py
Normal file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from evdev.ecodes import EV_KEY
|
||||
|
||||
from inputremapper.configs.keyboard_layout import keyboard_layout
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.task import Task
|
||||
|
||||
|
||||
class KeyDownTask(Task):
|
||||
"""Press the symbol."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="symbol",
|
||||
position=0,
|
||||
types=[str],
|
||||
is_symbol=True,
|
||||
)
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
symbol = self.get_argument("symbol").get_value()
|
||||
code = keyboard_layout.get(symbol)
|
||||
callback(EV_KEY, code, 1)
|
||||
45
inputremapper/injection/macros/tasks/key_up.py
Normal file
45
inputremapper/injection/macros/tasks/key_up.py
Normal file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from evdev.ecodes import EV_KEY
|
||||
|
||||
from inputremapper.configs.keyboard_layout import keyboard_layout
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.task import Task
|
||||
|
||||
|
||||
class KeyUpTask(Task):
|
||||
"""Release the symbol."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="symbol",
|
||||
position=0,
|
||||
types=[str],
|
||||
is_symbol=True,
|
||||
)
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
symbol = self.get_argument("symbol").get_value()
|
||||
code = keyboard_layout.get(symbol)
|
||||
callback(EV_KEY, code, 0)
|
||||
140
inputremapper/injection/macros/tasks/mod_tap.py
Normal file
140
inputremapper/injection/macros/tasks/mod_tap.py
Normal file
@ -0,0 +1,140 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from collections import deque
|
||||
from typing import Deque
|
||||
|
||||
from evdev.ecodes import EV_KEY
|
||||
|
||||
from inputremapper.configs.keyboard_layout import keyboard_layout
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.task import Task
|
||||
from inputremapper.input_event import InputEvent
|
||||
from inputremapper.logging.logger import logger
|
||||
|
||||
|
||||
class ModTapTask(Task):
|
||||
"""If pressed long enough in combination with other keys, it turns into a modifier.
|
||||
|
||||
Can be used to make home-row-modifiers.
|
||||
|
||||
Works similar to the default of
|
||||
https://github.com/qmk/qmk_firmware/blob/78a0adfbb4d2c4e12f93f2a62ded0020d406243e/docs/tap_hold.md#comparison-comparison
|
||||
"""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="default",
|
||||
position=0,
|
||||
types=[str],
|
||||
is_symbol=True,
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="modifier",
|
||||
position=1,
|
||||
types=[str],
|
||||
is_symbol=True,
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="tapping_term",
|
||||
position=2,
|
||||
types=[int, float],
|
||||
default=200,
|
||||
),
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
tapping_term = self.get_argument("tapping_term").get_value() / 1000
|
||||
jamming_asyncio_events: Deque[asyncio.Event] = deque()
|
||||
|
||||
async def listener(event: InputEvent) -> None:
|
||||
trigger = self.mapping.input_combination[-1]
|
||||
if event.type_and_code == trigger.type_and_code:
|
||||
# We don't block the event that would set _trigger_release_event.
|
||||
return
|
||||
|
||||
if event.type != EV_KEY:
|
||||
return
|
||||
|
||||
asyncio_event = asyncio.Event()
|
||||
jamming_asyncio_events.append(asyncio_event)
|
||||
# Make the EventReader wait until the mod_tap macro allows it to continue
|
||||
# processing the event. Because we want to wait until mod_tap injected the
|
||||
# modifier.
|
||||
await asyncio_event.wait()
|
||||
|
||||
self.add_event_listener(listener)
|
||||
|
||||
timeout = asyncio.Task(asyncio.sleep(tapping_term))
|
||||
await asyncio.wait(
|
||||
[asyncio.Task(self._trigger_release_event.wait()), timeout],
|
||||
return_when=asyncio.FIRST_COMPLETED,
|
||||
)
|
||||
has_timed_out = timeout.done()
|
||||
|
||||
if has_timed_out:
|
||||
# The timeout happened before the trigger got released.
|
||||
# We therefore modify stuff.
|
||||
symbol = self.get_argument("modifier").get_value()
|
||||
logger.debug("Modifying with %s", symbol)
|
||||
else:
|
||||
# The trigger got released before the timeout.
|
||||
# We therefore do not modify stuff.
|
||||
symbol = self.get_argument("default").get_value()
|
||||
logger.debug("Writing default %s", symbol)
|
||||
|
||||
code = keyboard_layout.get(symbol)
|
||||
callback(EV_KEY, code, 1)
|
||||
await self.keycode_pause()
|
||||
|
||||
# Now that we know if the key was pressed with the intention of modifying other
|
||||
# keys, we can let the jammed keys go on their journey through the handlers.
|
||||
# Those other handlers may map them to other keys and stuff.
|
||||
while len(jamming_asyncio_events) > 0:
|
||||
asyncio_event = jamming_asyncio_events.popleft()
|
||||
asyncio_event.set()
|
||||
await self.keycode_pause()
|
||||
await self.throttle()
|
||||
# While we are emptying the queue, more events might still arrive and add
|
||||
# to the queue.
|
||||
|
||||
# We remove this as late as possible, because if more keys are pressed while
|
||||
# jamming_asyncio_events is still being taken care of, they should wait until
|
||||
# all is done. This ensures the order of all events that are pressed, until
|
||||
# mod_tap is completely finished.
|
||||
self.remove_event_listener(listener)
|
||||
|
||||
# Keep the modifier pressed until the input/trigger is released
|
||||
await self._trigger_release_event.wait()
|
||||
callback(EV_KEY, code, 0)
|
||||
|
||||
await self.keycode_pause()
|
||||
|
||||
async def throttle(self) -> None:
|
||||
# In case the keycode_pause ist set to 0ms, we need to give the event handlers
|
||||
# a chance to inject the withheld events, before we go on. This ensures the
|
||||
# correct order of injections. Since we are using asyncio, something like
|
||||
# `callback(EV_KEY, code, 0)` might be faster than the event handlers, even if
|
||||
# it is the last step of the macro.
|
||||
if self.mapping.macro_key_sleep_ms == 0:
|
||||
await asyncio.sleep(0.01)
|
||||
57
inputremapper/injection/macros/tasks/modify.py
Normal file
57
inputremapper/injection/macros/tasks/modify.py
Normal file
@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from evdev.ecodes import EV_KEY
|
||||
|
||||
from inputremapper.configs.keyboard_layout import keyboard_layout
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.macro import Macro
|
||||
from inputremapper.injection.macros.task import Task
|
||||
|
||||
|
||||
class ModifyTask(Task):
|
||||
"""Do stuff while a modifier is activated."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="modifier",
|
||||
position=0,
|
||||
types=[str],
|
||||
is_symbol=True,
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="macro",
|
||||
position=1,
|
||||
types=[Macro],
|
||||
),
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
modifier = self.get_argument("modifier").get_value()
|
||||
code = keyboard_layout.get(modifier)
|
||||
macro = self.get_argument("macro").get_value()
|
||||
|
||||
callback(EV_KEY, code, 1)
|
||||
await self.keycode_pause()
|
||||
await macro.run(callback)
|
||||
callback(EV_KEY, code, 0)
|
||||
await self.keycode_pause()
|
||||
69
inputremapper/injection/macros/tasks/mouse.py
Normal file
69
inputremapper/injection/macros/tasks/mouse.py
Normal file
@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from evdev._ecodes import REL_Y, REL_X
|
||||
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.macro import InjectEventCallback
|
||||
from inputremapper.injection.macros.tasks.mouse_xy import MouseXYTask
|
||||
|
||||
|
||||
class MouseTask(MouseXYTask):
|
||||
"""Move the mouse cursor."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="direction",
|
||||
position=0,
|
||||
types=[str],
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="speed",
|
||||
position=1,
|
||||
types=[int, float],
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="acceleration",
|
||||
position=2,
|
||||
types=[int, float],
|
||||
default=1,
|
||||
),
|
||||
]
|
||||
|
||||
async def run(self, callback: InjectEventCallback) -> None:
|
||||
direction = self.get_argument("direction").get_value()
|
||||
speed = self.get_argument("speed").get_value()
|
||||
acceleration = self.get_argument("acceleration").get_value()
|
||||
|
||||
code, direction = {
|
||||
"up": (REL_Y, -1),
|
||||
"down": (REL_Y, 1),
|
||||
"left": (REL_X, -1),
|
||||
"right": (REL_X, 1),
|
||||
}[direction.lower()]
|
||||
|
||||
await self.axis(
|
||||
code,
|
||||
direction * speed,
|
||||
acceleration,
|
||||
callback,
|
||||
)
|
||||
99
inputremapper/injection/macros/tasks/mouse_xy.py
Normal file
99
inputremapper/injection/macros/tasks/mouse_xy.py
Normal file
@ -0,0 +1,99 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from typing import Union
|
||||
|
||||
from evdev._ecodes import REL_Y, REL_X
|
||||
from evdev.ecodes import EV_REL
|
||||
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.macro import InjectEventCallback
|
||||
from inputremapper.injection.macros.task import Task
|
||||
from inputremapper.injection.macros.tasks.util import precise_iteration_frequency
|
||||
|
||||
|
||||
class MouseXYTask(Task):
|
||||
"""Move the mouse cursor."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="x",
|
||||
position=0,
|
||||
types=[int, float],
|
||||
default=0,
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="y",
|
||||
position=1,
|
||||
types=[int, float],
|
||||
default=0,
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="acceleration",
|
||||
position=2,
|
||||
types=[int, float],
|
||||
default=1,
|
||||
),
|
||||
]
|
||||
|
||||
async def run(self, callback: InjectEventCallback) -> None:
|
||||
x = self.get_argument("x").get_value()
|
||||
y = self.get_argument("y").get_value()
|
||||
acceleration = self.get_argument("acceleration").get_value()
|
||||
await asyncio.gather(
|
||||
self.axis(REL_X, x, acceleration, callback),
|
||||
self.axis(REL_Y, y, acceleration, callback),
|
||||
)
|
||||
|
||||
async def axis(
|
||||
self,
|
||||
code: int,
|
||||
speed: Union[int, float],
|
||||
fractional_acceleration: Union[int, float],
|
||||
callback: InjectEventCallback,
|
||||
) -> None:
|
||||
acceleration = speed * fractional_acceleration
|
||||
direction = -1 if speed < 0 else 1
|
||||
current_speed = 0.0
|
||||
displacement_accumulator = 0.0
|
||||
displacement = 0
|
||||
if acceleration <= 0:
|
||||
displacement = int(speed)
|
||||
|
||||
async for _ in precise_iteration_frequency(self.mapping.rel_rate):
|
||||
if not self.is_holding():
|
||||
return
|
||||
|
||||
# Cursors can only move by integers. To get smooth acceleration for
|
||||
# small acceleration values, the cursor needs to move by a pixel every
|
||||
# few iterations. This can be achieved by remembering the decimal
|
||||
# places that were cast away, and using them for the next iteration.
|
||||
if acceleration:
|
||||
current_speed += acceleration
|
||||
current_speed = direction * min(abs(current_speed), abs(speed))
|
||||
displacement_accumulator += current_speed
|
||||
displacement = int(displacement_accumulator)
|
||||
displacement_accumulator -= displacement
|
||||
|
||||
if displacement != 0:
|
||||
callback(EV_REL, code, displacement)
|
||||
45
inputremapper/injection/macros/tasks/parallel.py
Normal file
45
inputremapper/injection/macros/tasks/parallel.py
Normal file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from typing import List
|
||||
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig, ArgumentFlags
|
||||
from inputremapper.injection.macros.macro import Macro, InjectEventCallback
|
||||
from inputremapper.injection.macros.task import Task
|
||||
|
||||
|
||||
class ParallelTask(Task):
|
||||
"""Run all provided macros in parallel."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="*macros",
|
||||
position=ArgumentFlags.spread,
|
||||
types=[Macro],
|
||||
),
|
||||
]
|
||||
|
||||
async def run(self, callback: InjectEventCallback) -> None:
|
||||
macros: List[Macro] = self.get_argument("*macros").get_values()
|
||||
coroutines = [macro.run(callback) for macro in macros]
|
||||
await asyncio.gather(*coroutines)
|
||||
49
inputremapper/injection/macros/tasks/repeat.py
Normal file
49
inputremapper/injection/macros/tasks/repeat.py
Normal file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.macro import Macro
|
||||
from inputremapper.injection.macros.task import Task
|
||||
|
||||
|
||||
class RepeatTask(Task):
|
||||
"""Repeat macros."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="repeats",
|
||||
position=0,
|
||||
types=[int],
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="macro",
|
||||
position=1,
|
||||
types=[Macro],
|
||||
),
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
repeats = self.get_argument("repeats").get_value()
|
||||
macro = self.get_argument("macro").get_value()
|
||||
|
||||
for _ in range(repeats):
|
||||
await macro.run(callback)
|
||||
49
inputremapper/injection/macros/tasks/set.py
Normal file
49
inputremapper/injection/macros/tasks/set.py
Normal file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.macro import macro_variables
|
||||
from inputremapper.injection.macros.task import Task
|
||||
|
||||
|
||||
class SetTask(Task):
|
||||
"""Set a variable to a certain value."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="variable",
|
||||
position=0,
|
||||
types=[str, float, int, None],
|
||||
is_variable_name=True,
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="value",
|
||||
position=1,
|
||||
types=[str, float, int, None],
|
||||
default=None,
|
||||
),
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
value = self.get_argument("value").get_value()
|
||||
assert macro_variables.is_alive()
|
||||
self.arguments["variable"].set_value(value)
|
||||
56
inputremapper/injection/macros/tasks/toggle.py
Normal file
56
inputremapper/injection/macros/tasks/toggle.py
Normal file
@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.macro import Macro
|
||||
from inputremapper.injection.macros.task import Task
|
||||
|
||||
|
||||
class ToggleTask(Task):
|
||||
"""Toggle macros."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="macro",
|
||||
position=0,
|
||||
types=[Macro],
|
||||
),
|
||||
]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.trigger_count = 0
|
||||
|
||||
def press_trigger(self) -> None:
|
||||
Task.press_trigger(self)
|
||||
self.trigger_count += 1
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
macro = self.get_argument("macro").get_value()
|
||||
|
||||
while self.trigger_count <= 1:
|
||||
await macro.run(callback)
|
||||
await asyncio.sleep(1 / 1000)
|
||||
|
||||
self.trigger_count = 0
|
||||
45
inputremapper/injection/macros/tasks/util.py
Normal file
45
inputremapper/injection/macros/tasks/util.py
Normal file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
from typing import AsyncIterator
|
||||
|
||||
|
||||
async def precise_iteration_frequency(frequency: float) -> AsyncIterator[None]:
|
||||
"""A generator to iterate over in a fixed frequency.
|
||||
|
||||
asyncio.sleep might end up sleeping too long, for whatever reason. Maybe there are
|
||||
other async function calls that take longer than expected in the background.
|
||||
"""
|
||||
sleep = 1 / frequency
|
||||
corrected_sleep = sleep
|
||||
error = 0.0
|
||||
|
||||
while True:
|
||||
start = time.time()
|
||||
|
||||
yield
|
||||
|
||||
corrected_sleep -= error
|
||||
await asyncio.sleep(corrected_sleep)
|
||||
error = (time.time() - start) - sleep
|
||||
54
inputremapper/injection/macros/tasks/wait.py
Normal file
54
inputremapper/injection/macros/tasks/wait.py
Normal file
@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import random
|
||||
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.task import Task
|
||||
|
||||
|
||||
class WaitTask(Task):
|
||||
"""Wait time in milliseconds."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="time",
|
||||
position=0,
|
||||
types=[float, int],
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="max_time",
|
||||
position=1,
|
||||
types=[float, int, None],
|
||||
default=None,
|
||||
),
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
time = self.get_argument("time").get_value()
|
||||
max_time = self.get_argument("max_time").get_value()
|
||||
|
||||
if max_time is not None and max_time > time:
|
||||
time = random.uniform(time, max_time)
|
||||
|
||||
await asyncio.sleep(time / 1000)
|
||||
76
inputremapper/injection/macros/tasks/wheel.py
Normal file
76
inputremapper/injection/macros/tasks/wheel.py
Normal file
@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# input-remapper - GUI for device specific keyboard mappings
|
||||
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
|
||||
#
|
||||
# This file is part of input-remapper.
|
||||
#
|
||||
# input-remapper is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# input-remapper is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
|
||||
from evdev.ecodes import (
|
||||
EV_REL,
|
||||
REL_WHEEL_HI_RES,
|
||||
REL_HWHEEL_HI_RES,
|
||||
REL_WHEEL,
|
||||
REL_HWHEEL,
|
||||
)
|
||||
|
||||
from inputremapper.injection.macros.argument import ArgumentConfig
|
||||
from inputremapper.injection.macros.task import Task
|
||||
from inputremapper.injection.macros.tasks.util import precise_iteration_frequency
|
||||
|
||||
|
||||
class WheelTask(Task):
|
||||
"""Move the scroll wheel."""
|
||||
|
||||
argument_configs = [
|
||||
ArgumentConfig(
|
||||
name="direction",
|
||||
position=0,
|
||||
types=[str],
|
||||
),
|
||||
ArgumentConfig(
|
||||
name="speed",
|
||||
position=1,
|
||||
types=[int, float],
|
||||
),
|
||||
]
|
||||
|
||||
async def run(self, callback) -> None:
|
||||
direction = self.get_argument("direction").get_value()
|
||||
|
||||
# 120, see https://www.kernel.org/doc/html/latest/input/event-codes.html#ev-rel
|
||||
code, value = {
|
||||
"up": ([REL_WHEEL, REL_WHEEL_HI_RES], [1 / 120, 1]),
|
||||
"down": ([REL_WHEEL, REL_WHEEL_HI_RES], [-1 / 120, -1]),
|
||||
"left": ([REL_HWHEEL, REL_HWHEEL_HI_RES], [1 / 120, 1]),
|
||||
"right": ([REL_HWHEEL, REL_HWHEEL_HI_RES], [-1 / 120, -1]),
|
||||
}[direction.lower()]
|
||||
|
||||
speed = self.get_argument("speed").get_value()
|
||||
remainder = [0.0, 0.0]
|
||||
|
||||
async for _ in precise_iteration_frequency(self.mapping.rel_rate):
|
||||
if not self.is_holding():
|
||||
return
|
||||
|
||||
for i in range(0, 2):
|
||||
float_value = value[i] * speed + remainder[i]
|
||||
remainder[i] = math.fmod(float_value, 1)
|
||||
if abs(float_value) >= 1:
|
||||
callback(EV_REL, code[i], int(float_value))
|
||||
Reference in New Issue
Block a user