felix_f
New Member
Hi, I would like to remap some keys from a second keyboard using python to use them as macro keys for other apps (mainly obs). I have the script mostly done, but I have a problem simulating a key press that is not used already, and that obs will actually like. As you can see below, I can either use evdev directly from python, or just call xdotool, but neither of them work in obs, but they do in kde settings for example. I am using F23, because according to this, F Keys up to 35 should work.
Python:
from evdev import InputDevice, categorize, ecodes, uinput
import subprocess
dev = InputDevice('/dev/input/by-id/usb-04d9_1400-event-kbd') # location of usb device
print(dev)
dev.grab()
for event in dev.read_loop():
if event.type == ecodes.EV_KEY:
key = categorize(event)
if key.keystate == key.key_down:
##print(key.keycode)
if key.keycode == 'KEY_ESC':
print('ESC')
# subprocess.call(['xdotool', 'key', 'F23']) #(option 1)
# with uinput.UInput() as ui #(option 2)
# ui.write(ecodes.EV_KEY, ecodes.KEY_F23, 1)
# ui.syn()