Skip to content

Instantly share code, notes, and snippets.

@lezed1
Last active December 24, 2020 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lezed1/aa4918d6b5e6bd638e7c325c0ed44e7a to your computer and use it in GitHub Desktop.
Save lezed1/aa4918d6b5e6bd638e7c325c0ed44e7a to your computer and use it in GitHub Desktop.
Recreate Razer Synapse's Reactive Firefly mousepad effect with any mouse!
import colorsys
import time
from random import random
from razer.client import DeviceManager
from pynput import mouse
razer_device_manager = DeviceManager()
for device in razer_device_manager.devices:
if device.type == "firefly":
firefly = device
break
else:
raise Exception("Could not find firefly!")
last_time = {
"color": time.time(),
"react": time.time()
}
def react(x, y, button=None, down=None):
global last_time
print(x, y, button, down)
this_time = time.time()
# Don't change color on button release
if (down or down == -1) and this_time - last_time["color"] > 0.1:
color = list(map(lambda x: int(x * 255), colorsys.hsv_to_rgb(random(), 1, 1)))
firefly.fx.reactive(color[0], color[1], color[2], 1)
last_time["color"] = this_time
if this_time - last_time["react"] > 0.05:
firefly.trigger_reactive()
last_time["react"] = this_time
while True:
try:
with mouse.Listener(on_click=react, on_move=react, on_scroll=react) as mouse_listener:
mouse_listener.join()
except Exception as e:
print(e)
import colorsys
from random import random
from razer.client import DeviceManager
from pynput import mouse
razer_device_manager = DeviceManager()
for device in razer_device_manager.devices:
if device.type == "firefly":
firefly = device
break
else:
raise Exception("Could not find firefly!")
def react(x, y, button, down):
print(x, y, button, down)
# Don't change color on button release
if down:
color = list(map(lambda x: int(x * 255), colorsys.hsv_to_rgb(random(), 1, 1)))
firefly.fx.reactive(color[0], color[1], color[2], 1)
firefly.trigger_reactive()
while True:
try:
with mouse.Listener(
on_click=react) as mouse_listener:
mouse_listener.join()
except Exception as e:
print(e)
Copy link

ghost commented May 2, 2017

sorry can you help me to understand these code

@wico
Copy link

wico commented Jan 30, 2018

Btw., line 10, the device.type reports "mousemat", not "firefly". Just fyi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment