I sometimes play IL2 Sturmovik (flight simulator with WWII planes) without a joystick and it doesn't have mouse as joystick support. I used PPJoy and GlovePIE for that but recently installed Win 7 64 and I don't want to use that signing test mode for PPJoy.
So I switched to FreePIE and vJoy, but the problem with some scripts I found online is that the mouse.deltax keeps adding even if the cursor is on the limit of the screen. So of course, when you come back to the middle of the screen, the cursor is centered but the joystick is not anymore... not to mention you have to start FreePIE with the cursor centered and so on... so no go.
I thought I could set some limits and so on but the mouse.deltax keeps drifting no matter what.
Then I thought FreePIE uses Python, did some search online, and found this script where we can read screen size and a cursor position that runs from 0 on the left of the screen, to maximum resolution to the right (I'm talking about X axis now). This is it: http://nullege.com/codes/show/src@m@o@m ... tCursorPos
So I just wrote the code below and now I have the cursor in game in the middle of the screen telling me that the vJoy axis are also centered. The only downside is that you have to calibrate (I initially thought about adding some values that each user ca change to max. controls on screen boundaries) but there's not much to it, just focus the next button in "Calibrate" window for USB joystiks, move the mouse to the top and bottom and left to right when setting X/Y axis and hit ENTER to save setting.
Hope it helps

Code: Select all
from System import Int16
from ctypes import windll, Structure, c_ulong, byref
class POINT(Structure):
_fields_ = [("x", c_ulong), ("y", c_ulong)]
if starting:
vJoy0_stat = 0
vJoy[0].x = 0
mouse_x = 0
mouse_y = 0
screen_x = windll.user32.GetSystemMetrics(0)
screen_y = windll.user32.GetSystemMetrics(1)
pt = POINT()
if keyboard.getPressed(Key.CapsLock): // enable/disable mouse vJoy X/Y control by pressing CapsLock
if vJoy0_stat == 0: vJoy0_stat = 1
else: vJoy0_stat = 0
if vJoy0_stat == 1:
windll.user32.GetCursorPos(byref(pt))
mouse_x = pt.x
mouse_y = pt.y
vJoy[0].x = mouse_x - (screen_x / 2)
vJoy[0].y = mouse_y - (screen_y / 2)
#diagnostics.watch(screen_x)
#diagnostics.watch(screen_y)
#diagnostics.watch(mouse_x)
#diagnostics.watch(mouse_y)
diagnostics.watch(vJoy[0].x)
diagnostics.watch(vJoy[0].y)