Re: Event-driven / callback programming of mouse or keyboard
Bruce Sherwood <[email protected]> Mon, 21 May 2012 17:03:46 -0600
| Newsgroups | gmane.comp.python.visualpython.user |
|---|---|
| Message-ID | <CAFDG03hJ4jk_K7pzEUfiy0q1mC3M8f1ZekZgtLZpU8LHqGLY2g@mail.gmail.com> |
I too thought of a way to introduce a callback, by using threads (this
is based on the scheme used in the graphing module, vis/graph.py, to
enable the feature that dragging the mouse shows crosshairs on a
graph).
from visual import *
import time
from threading import Thread, RLock
lock = RLock()
run = True
class timer(Thread): # This timer thread watches for mouse events.
def run(self):
global run
while True:
time.sleep(0.05)
lock.acquire()
if scene.mouse.clicked:
scene.mouse.getclick()
run = not run
lock.release()
b = box()
thr = timer()
thr.start()
while True:
rate(100)
if run: b.rotate(angle=.01, axis=(0,1,0))
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/