View Single Post
  #2  
Old 01-28-2009, 04:05 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
The following script shows how to use a wiimote to control the mouse movement and simulate mouse button presses:
Code:
import viz
import win32api
import win32con

viz.go()

#Create wii extension
wii = viz.add('wiimote.dle')

#Connect to wiimote
wiimote = wii.addWiimote()
if not wiimote.valid():
	sys.exit()
	
#Use wiimote button B to simulate left mouse click
def SimulateMouseButton(button):
	win32api.mouse_event(button,0,0,0)
vizact.onsensordown(wiimote,wii.BUTTON_B,SimulateMouseButton,win32con.MOUSEEVENTF_LEFTDOWN)
vizact.onsensorup(wiimote,wii.BUTTON_B,SimulateMouseButton,win32con.MOUSEEVENTF_LEFTUP)

#Use wiimote IR sensor position to simulate mouse movement
def SimulateMouseMove():
	x,y = wiimote.posIR
	win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE|win32con.MOUSEEVENTF_MOVE,int(65535*x),int(65535*(1.0-y)),0)
vizact.ontimer(0,SimulateMouseMove)
Reply With Quote