import OSC
from OSC1 import OSCServer
import sys
from time import sleep
import SendKeys
server = OSCServer( ("localhost", 5002) )
server.timeout = 0
run = True
# this method of reporting timeouts only works by convention
# that before calling handle_request() field .timed_out is
# set to False
def handle_timeout(self):
self.timed_out = True
def user_callback(path, tags, args, source):
# which user will be determined by path:
# we just throw away all slashes and join together what's left
user = ''.join(path.split("/"))
# tags will contain 'fff'
# args is a OSCMessage with data
# source is where the message came from (in case you need to reply)
if args[0] == 1:
SendKeys.SendKeys("K")
# funny python's way to add a method to an instance of a class
import types
server.handle_timeout = types.MethodType(handle_timeout, server)
server.addMsgHandler( "/muse/elements/blink", user_callback )
def each_frame():
server.timed_out = False
while not server.timed_out:
server.handle_request()
# simulate a "game engine"
while run:
each_frame()
server.close()
Comments
Please log in or sign up to comment.