# # # WHY DID WRITE SCRIPT ? : GAMES ! # WINETRICKS MWO=FORCE but want to use GAME MENUS with MOUSE # example SWAT4 , need to use menu in game to start shooting baddies !! but need MWO=FORCE in game ?? # # PLATFORM : linux # REQUIRES : python python-xlib xdotool # AUTHOR : terry.cadd@xxxxxxxxx # DATE : Thu Apr 7 22:28:38 BST 2011 # VERSION : 1 # # USAGE : # start this script then play the game # numpad moves mouse , 4 left , 6 right , 8 up , 2 down , 5 clicks mouse # numpad enter exits script # # values for key_up , key_left , key_down , key_right were found from # xev utility . (the keycode value.) # # BEHAVIOUR : # mouse cursor will flicker because there are now two things controlling the mouse # this script and usual x windows mouse # # FEEDBACK : welcome ! # # AIMS : wonder if this get put into winetricks package ?!? # from subprocess import call import os import sys import time from Xlib import X, display mouse = {} mouse['x'] = 100 mouse['y'] = 100 if len(sys.argv) >= 2 : mouse['x'] = int(sys.argv[1]) if len(sys.argv) >= 3 : mouse['y'] = int(sys.argv[2]) print "keeping mouse at (" , mouse['x'] , "," , mouse['y'] , ")" print "typeof mouse x " , type(mouse['x']) print "typeof mouse y " , type(mouse['y']) # custom keys to control mouse key_up = 80 key_down = 88 key_left = 83 key_right = 85 key_click = 84 key_exit = 104 keys = [key_up,key_down,key_left,key_right,key_click,key_exit] smallstep = 5 def pointerLeft(): mouse['x'] = mouse['x'] - smallstep def pointerRight(): mouse['x'] = mouse['x'] + smallstep def pointerUp(): mouse['y'] = mouse['y'] - smallstep def pointerDown(): mouse['y'] = mouse['y'] + smallstep def pointerClick(): os.system("xdotool mousemove " + str(mouse['x']) + " " + str(mouse['y']) + " click 1") def handle_event(aEvent): keycode = aEvent.detail if aEvent.type == X.KeyPress: # smaller mouse jumps from keyboard if keycode == key_up: pointerUp() elif keycode == key_left: pointerLeft() elif keycode == key_right: pointerRight() elif keycode == key_down: pointerDown() elif keycode == key_click: pointerClick() elif keycode == key_exit: exit() else : print "keycode = " , keycode start = time.time() d = display.Display() s = d.screen() root = s.root # catch keyPress events root.change_attributes(event_mask = X.KeyPressMask) for keycode in keys: root.grab_key(keycode, X.AnyModifier, 1,X.GrabModeAsync, X.GrabModeAsync) while True : root.warp_pointer(mouse['x'],mouse['y']) d.sync() elapsed = (time.time() - start) event = root.display.next_event() handle_event(event)