Created
June 21, 2023 17:50
-
-
Save Jacajack/db3823646b77258ca4560a058bac2fbb to your computer and use it in GitHub Desktop.
Python evdev script for handling BlackWidow V4's command dial (when mapped to horizontal scroll)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import asyncio | |
import evdev | |
import evdev.ecodes as ecodes | |
import openrazer.client | |
import colorsys | |
devman = openrazer.client.DeviceManager() | |
print(devman.devices) | |
kbd = devman.devices[0] | |
mouse = evdev.InputDevice("/dev/input/by-id/usb-Razer_Razer_BlackWidow_V4_Pro-if02-event-mouse") | |
virtual_mouse = evdev.UInput.from_device(mouse, name="virtual-mouse") | |
mouse.grab() | |
total_dial = 0 | |
def command_dial(delta): | |
global total_dial | |
print(f"command_dial({delta})") | |
total_dial = total_dial + delta | |
col = tuple(x * 255 for x in colorsys.hsv_to_rgb(total_dial % 128 / 128.0, 1, 1)) | |
for y in range(8): | |
for x in range(22): | |
kbd.fx.advanced.matrix[y, x] = col | |
kbd.fx.advanced.draw() | |
async def handle_mouse(): | |
async for event in mouse.async_read_loop(): | |
if event.type == ecodes.EV_REL and event.code == ecodes.REL_HWHEEL: | |
command_dial(event.value) | |
virtual_mouse.write_event(event) | |
asyncio.ensure_future(handle_mouse()) | |
event_loop = asyncio.get_event_loop() | |
event_loop.run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment