1
0
Fork 0
mirror of https://github.com/dbarzin/pandora-box.git synced 2025-07-18 21:09:41 +02:00
pandora-box/tests/mouse-click-or-key.py

61 lines
1.4 KiB
Python
Raw Permalink Normal View History

2023-03-14 15:04:30 +01:00
#!/usr/bin/python3
import os
import sys
import time
2023-03-23 14:14:48 +01:00
import threading
2023-03-14 15:04:30 +01:00
2023-03-23 14:14:48 +01:00
mouseEvent = threading.Event()
enterEvent = threading.Event()
mouseOrEnterCondition = threading.Condition()
2023-03-14 15:04:30 +01:00
def mouseClickThread():
mouse = open("/dev/input/mice", "rb")
os.set_blocking(mouse.fileno(), False)
down = False
while not enterEvent.is_set():
buf = mouse.read(3)
if not (buf is None):
if ((buf[0] & 0x1) == 1):
down = True
if (((buf[0] & 0x1) == 0) and down):
break
2023-03-23 14:14:48 +01:00
time.sleep(0.1)
2023-03-14 15:04:30 +01:00
mouse.close()
mouseEvent.set()
with mouseOrEnterCondition:
mouseOrEnterCondition.notify()
def enterKeyThread():
os.set_blocking(sys.stdin.fileno(), False)
while not mouseEvent.is_set():
input = sys.stdin.readline()
if (len(input) > 0):
break
2023-03-23 14:14:48 +01:00
time.sleep(0.1)
2023-03-14 15:04:30 +01:00
enterEvent.set()
with mouseOrEnterCondition:
mouseOrEnterCondition.notify()
def waitMouseOrEnter():
with mouseOrEnterCondition:
2023-03-23 14:14:48 +01:00
threading.Thread(target=mouseClickThread, args=()).start()
threading.Thread(target=enterKeyThread, args=()).start()
2023-03-14 15:04:30 +01:00
mouseEvent.clear()
enterEvent.clear()
while not (mouseEvent.is_set() or enterEvent.is_set()):
mouseOrEnterCondition.wait()
2023-03-23 14:14:48 +01:00
print("Wait mouse click or enter")
2023-03-14 15:04:30 +01:00
waitMouseOrEnter()
2023-03-23 14:14:48 +01:00
print("Done.")