Created
March 3, 2020 13:41
-
-
Save bergie/9a85e24c9a4323781827c3e0b982e488 to your computer and use it in GitHub Desktop.
Get click/doubleclick from Bluetooth shutter button
This file contains 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
import asyncio | |
import threading | |
from evdev import InputDevice, categorize, ecodes | |
dev = InputDevice('/dev/input/event1') | |
clicks = 0 | |
timer = None | |
def count_clicks(): | |
global clicks, timer | |
if clicks > 1: | |
print("Double click") | |
else: | |
print("Click") | |
clicks = 0 | |
timer = None | |
async def helper(dev): | |
global clicks, timer | |
async for ev in dev.async_read_loop(): | |
if ev.type == ecodes.EV_KEY: | |
data = categorize(ev) | |
if data.keystate == 1 and data.scancode == 115: | |
clicks = clicks + 1 | |
if not timer: | |
timer = threading.Timer(0.3, count_clicks) | |
timer.start() | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(helper(dev)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment