|
|
@ -25,49 +25,34 @@
|
|
|
|
import asyncio
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
|
|
from keymapper.logger import logger
|
|
|
|
from keymapper.logger import logger
|
|
|
|
from keymapper.state import system_mapping, KEYCODE_OFFSET
|
|
|
|
from keymapper.state import KEYCODE_OFFSET
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handle_keycode(mapping, macros, event, uinput):
|
|
|
|
def handle_keycode(code_code_mapping, macros, event, uinput):
|
|
|
|
"""Write the mapped keycode."""
|
|
|
|
"""Write the mapped keycode."""
|
|
|
|
input_keycode = event.code + KEYCODE_OFFSET
|
|
|
|
input_keycode = event.code
|
|
|
|
character = mapping.get_character(input_keycode)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if character is None:
|
|
|
|
if input_keycode in macros:
|
|
|
|
# unknown keycode, forward it
|
|
|
|
macro = macros[input_keycode]
|
|
|
|
target_keycode = input_keycode
|
|
|
|
|
|
|
|
elif macros.get(input_keycode) is not None:
|
|
|
|
|
|
|
|
if event.value == 0:
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
logger.spam(
|
|
|
|
logger.spam(
|
|
|
|
'got code:%s value:%s, maps to macro %s',
|
|
|
|
'got code:%s value:%s, maps to macro %s',
|
|
|
|
event.code + KEYCODE_OFFSET,
|
|
|
|
event.code + KEYCODE_OFFSET,
|
|
|
|
event.value,
|
|
|
|
event.value,
|
|
|
|
character
|
|
|
|
macro.code
|
|
|
|
)
|
|
|
|
)
|
|
|
|
macro = macros.get(input_keycode)
|
|
|
|
asyncio.ensure_future(macro.run())
|
|
|
|
if macro is not None:
|
|
|
|
|
|
|
|
asyncio.ensure_future(macro.run())
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
|
|
|
|
# TODO compile int-int mapping instead of going this route.
|
|
|
|
|
|
|
|
# I think that makes the reverse mapping obsolete.
|
|
|
|
|
|
|
|
# It already is actually.
|
|
|
|
|
|
|
|
target_keycode = system_mapping.get(character)
|
|
|
|
|
|
|
|
if target_keycode is None:
|
|
|
|
|
|
|
|
logger.error(
|
|
|
|
|
|
|
|
'Don\'t know what %s maps to',
|
|
|
|
|
|
|
|
character
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if input_keycode in code_code_mapping:
|
|
|
|
|
|
|
|
target_keycode = code_code_mapping[input_keycode]
|
|
|
|
logger.spam(
|
|
|
|
logger.spam(
|
|
|
|
'got code:%s value:%s, maps to code:%s char:%s',
|
|
|
|
'got code:%s value:%s, maps to code:%s',
|
|
|
|
event.code + KEYCODE_OFFSET,
|
|
|
|
event.code + KEYCODE_OFFSET,
|
|
|
|
event.value,
|
|
|
|
event.value,
|
|
|
|
target_keycode,
|
|
|
|
target_keycode
|
|
|
|
character
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
target_keycode = input_keycode
|
|
|
|
|
|
|
|
|
|
|
|
uinput.write(event.type, target_keycode - KEYCODE_OFFSET, event.value)
|
|
|
|
uinput.write(event.type, target_keycode, event.value)
|
|
|
|
uinput.syn()
|
|
|
|
uinput.syn()
|
|
|
|