mirror of
https://github.com/dbarzin/pandora-box.git
synced 2025-07-19 13:29:42 +02:00
work on wait key
This commit is contained in:
parent
cfde07c9c6
commit
414cd61569
2 changed files with 80 additions and 0 deletions
62
tests/mouse-click-or-key.py
Executable file
62
tests/mouse-click-or-key.py
Executable file
|
@ -0,0 +1,62 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
from threading import Thread, Event, Condition
|
||||||
|
|
||||||
|
mouseEvent = Event()
|
||||||
|
enterEvent = Event()
|
||||||
|
mouseOrEnterCondition = Condition()
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
time.sleep(0.5)
|
||||||
|
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
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
enterEvent.set()
|
||||||
|
with mouseOrEnterCondition:
|
||||||
|
mouseOrEnterCondition.notify()
|
||||||
|
|
||||||
|
|
||||||
|
def waitMouseOrEnter():
|
||||||
|
print("Wait mouse click or enter")
|
||||||
|
with mouseOrEnterCondition:
|
||||||
|
Thread(target=mouseClickThread, args=()).start()
|
||||||
|
Thread(target=enterKeyThread, args=()).start()
|
||||||
|
|
||||||
|
mouseEvent.clear()
|
||||||
|
enterEvent.clear()
|
||||||
|
while not (mouseEvent.is_set() or enterEvent.is_set()):
|
||||||
|
mouseOrEnterCondition.wait()
|
||||||
|
|
||||||
|
print("Done.")
|
||||||
|
|
||||||
|
|
||||||
|
waitMouseOrEnter()
|
18
tests/wait-key.py
Executable file
18
tests/wait-key.py
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import curses
|
||||||
|
|
||||||
|
screen = curses.initscr()
|
||||||
|
screen.keypad(1)
|
||||||
|
curses.curs_set(0)
|
||||||
|
curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
|
||||||
|
curses.flushinp()
|
||||||
|
curses.noecho()
|
||||||
|
screen.clear()
|
||||||
|
|
||||||
|
screen.addstr(1, 0, "Press any key")
|
||||||
|
|
||||||
|
screen.getch()
|
||||||
|
|
||||||
|
curses.endwin()
|
||||||
|
curses.flushinp()
|
Loading…
Add table
Add a link
Reference in a new issue