It seems when I pasted the script here a space was added between the c and the s in the lines:
screen_x = windll.user32.GetSystemMetric s(0)
screen_y = windll.user32.GetSystemMetric s(1)
It seems there is a bug in the forum software or something I don't understand. In the new script I pasted below I had to set some words to bold or the same would happen. I should have checked that what I post works, sorry. If script gives errors it is not running, so obviously the game won't see activity for the vJoy device.
In the meantime I changed more things. Now instead of "pressing" virtual buttons you "press" keys or key combinations. Easier to map controls in game that way: just map the keys. I tested this with Falcon BMS and I could eject no problem. :) . Axes don't work in AH for some reason, though. :(
I mapped the mouse wheel to the z axis. For throttle or rudder.
Big chance there are still bugs, need someone to find them! :D.
P.S. I changed the default key to enable the script. Now it is Scroll Lock.
P.S.2 They virtual joystick should show up and move in windows "game controllers" properties.
from System import Int16
from ctypes import windll, Structure, c_ulong, byref
class POINT(Structure):
_fields_ = [("x", c_ulong), ("y", c_ulong)]
if starting:
# Activate/deactivate script.
# Type Key. and FreePIE editor will show key suggestions.
toggle_key = Key.ScrollLock
# From 0 to 1. E.G. 0.1 = 10% dead zone in each direction: x+, x-, y+, y-.
deadzone = 0
# -1 to invert axes
x_direction = 1
y_direction = 1
# 0 or None to disable. You can set a key or a key combination.
# If you want a key combination such as Ctrl+Shift+u for right mouse button,
# for example, it would be:
# right_mouse = (Key.LeftControl, Key.LeftShift, Key.U)
left_button = None
right_button = None
middle_button = None
forward_button = None
back_button = None
wheel_up = None
wheel_down = None
# 0 or 1. Disables wheel_up and wheel_down mappings above, if set.
wheel_is_z_axis = 1
# -1 or 1
z_direction = 1
# This disables the mapping for the button if set above and wheel_is_axis is 1.
# Set to None/0 to disable.
reset_to_center_button = "middle_button"
# Percent in each direction: +z and -z (Sensitivity)
percent_increment_per_wheel_step = 10
# Initialization logic.
vJoy0_stat = 0
vjoy_min = -16382
vjoy_max = vjoy_min + Int16.MaxValue
zero_offset = 2
vJoy[0].x = vJoy[0].y = vJoy[0].z = zero_offset
mouse_x = mouse_y = 0
screen_x = windll.user32.GetSystemMetrics(0)
screen_y = windll.user32.GetSystemMetrics(1)
pt = POINT()
x_min = (screen_x - screen_y) / 2
x_max = x_min + screen_y - 1
btns = [None] * 5
wheel_increment = ((Int16.MaxValue + 1)/ 200.0 *
percent_increment_per_wheel_step )
button_n = {"left_button": 0, "right_button": 1,
"middle_button": 2, "forward_button": 3, "back_button": 4}
rtc_button = button_n.get(reset_to_center_button)
limits = (None, vjoy_max, vjoy_min)
for k, button in enumerate(
(left_button, right_button, middle_button, forward_button, back_button)):
if k == rtc_button and wheel_is_z_axis: continue
elif isinstance(button, tuple):
btns[k] = button
else:
btns[k] = (button, ) if isinstance(button, Key) else None
if not isinstance(wheel_down, tuple):
wheel_down = (wheel_down, ) if isinstance(wheel_down, Key) else ()
if not isinstance(wheel_up, tuple):
wheel_up = (wheel_up, ) if isinstance(wheel_up, Key) else ()
# Loop logic.
if keyboard.getPressed(toggle_key):
if vJoy0_stat == 0:
vJoy0_stat = 1
button_status = [0] * 5
z_val = zero_offset
else:
vJoy0_stat = 0
vJoy[0].x = vJoy[0].y = vJoy[0].z = zero_offset
for k, pressed in enumerate(button_status):
if pressed:
for key in reversed(btns[k]):
keyboard.setKeyUp(key)
if vJoy0_stat == 1:
windll.user32.GetCursorPos(byref(pt))
mouse_x = pt.x if x_direction == 1 else screen_x - pt.x
mouse_y = pt.y if y_direction == 1 else screen_y - pt.y
vJoy[0].x = int(round(filters.deadband(
filters.ensureMapRange(mouse_x, x_min, x_max, vjoy_min, vjoy_max),
deadzone, vjoy_min, vjoy_max)))
vJoy[0].y = int(round(filters.deadband(
filters.ensureMapRange(mouse_y, 0, screen_y -1, vjoy_min, vjoy_max),
deadzone, vjoy_min, vjoy_max)))
for k, keys in enumerate(btns):
if keys == None: continue
button_pressed = mouse.getButton(k)
if button_pressed != button_status[k]:
for key in keys:
keyboard.setKey(key, button_pressed)
button_status[k] = button_pressed
if wheel_is_z_axis:
if reset_to_center_button and mouse.getButton(rtc_button):
vJoy[0].z = z_val = zero_offset
elif mouse.wheel != 0:
if mouse.wheel > 0 and (
round(z_val) * z_direction < z_direction * limits[z_direction]):
z_val += wheel_increment * mouse.wheel / 120 * z_direction
elif mouse.wheel < 0 and (
round(z_val) * z_direction > z_direction * limits[-z_direction]):
z_val += wheel_increment * mouse.wheel / 120 * z_direction
vJoy[0].z = limits[1] if z_val > limits[1] else (
limits[2] if z_val < limits[2] else int(round(z_val)))
else:
if mouse.wheelDown:
for k in wheel_down:
keyboard.setPressed(k)
if mouse.wheelUp:
for k in wheel_up:
keyboard.setPressed(k)
if stopping:
vJoy[0].x = vJoy[0].y = vJoy[0].z = zero_offset