When I made PyMouse I did so because I had the idea to make an iPhone mouse. Today I had another crazy idea for moving the mouse: with a joystick!
It turns out it's quite easy to use the joystick via PyGame, so that is what I did this evening.
I plugged in the joystick from my brother, copied some PyGame example, imported my own PyMouse module and here is the result. You might need to tweak it a little to make it work with your joystick or game controller.
importpygamefrompymouseimportPyMousefromtimeimportsleep# edit this to reflect your joystick axis and buttons
action={'x':0,'y':1,'multiplier':3,'left':0,'right':1}pygame.init()j=pygame.joystick.Joystick(0)# first joystick
j.init()m=PyMouse()print'Initialized Joystick : %s'%j.get_name()state=[0,0]try:whileTrue:pygame.event.pump()sleep(0.1)# check if any button state has changed and change mouse state accordingly
ifj.get_button(action['left'])andnotstate[0]:state[0]=1print"left press"m.press(*m.position())elifnotj.get_button(action['left'])andstate[0]:state[0]=0print"left release"m.release(*m.position())elifj.get_button(action['right'])andnotstate[1]:state[1]=1print"right press"m.press(*m.position(),button=2)elifnotj.get_button(action['right'])andstate[1]:state[1]=0print"right release"m.release(*m.position(),button=2)x,y=m.position()m.move(# get_axis returns a value between -1 and 1
# fumble a bit here to reverse axis
x+(j.get_axis(action['x'])*50*abs(j.get_axis(action['multiplier'])-1)),y+(j.get_axis(action['y'])*50*abs(j.get_axis(action['multiplier'])-1)))exceptKeyboardInterrupt:j.quit()