Well, my script currently has three mode of mouse centering:
Hard centering, Auto-centering and, something I'm very proud of, a smart-centering when the cursor is near the center.
My mouse is defined this way:
Code: Select all
if starting:
relativemouse = True
max = Int16.MaxValue*0.5+2
min = -Int16.MaxValue*0.5+1
mx = 0
my = 0
a = 0
b = 0
c = 0
d = 0
sensitivity = 35
speed = 10 # auto-centering speed
pradius = 1200 # auto-centering radius
nradius = pradius - (pradius *2) # negative range radius, self defined
rm_speed = 250 # relative mouse speed
# pitch
my += mouse.deltaY * sensitivity
# yaw
mx += mouse.deltaX * sensitivity
Than, here are the three implementations I use:
Code: Select all
# Manual centering
if keyboard.getKeyDown(Key.LeftControl):
mx = 0
my = 0
##############################################
# Smart-centering when the mouse is close to the center, inside a predefined radius
##############################################
if (mx < pradius) and (mx > 0):
mx = mx - speed
elif (mx > nradius) and (mx < 0):
mx = mx + speed
if (my < pradius) and (my > 0):
my = my - speed
elif (my > nradius) and (my < 0):
my = my + speed
##############################################
# toggle relative mouse
##############################################
toggle = keyboard.getKeyDown(Key.LeftShift) and keyboard.getPressed(Key.Space)
if toggle:
relativemouse = not relativemouse
##############################################
# relative mouse (auto centering when idle)
##############################################
if (relativemouse):
a += mouse.deltaX
b += mouse.deltaX
if filters.stopWatch(True,600):
c = a + 0
if filters.stopWatch(True,30):
d = b + 0
if (c - d == 0):
if mx < -500:
mx += rm_speed
elif mx > 500:
mx -= rm_speed
if my < -500:
my += rm_speed
elif my > 500:
my -= rm_speed
##############################################
# Mouse to vJoy
##############################################
vJoy[1].x = filters.deadband(mx, 10)
vJoy[1].y = filters.deadband(my, 10)
Hope this helps!