yannbouteiller / vgamepad

Virtual XBox360 and DualShock4 gamepads in python
MIT License
162 stars 21 forks source link

not able to send vgamepad instructions to a game #15

Closed jibin23 closed 1 year ago

jibin23 commented 1 year ago

I am simulating moving the left joystick anti-clockwise. I am able to see this being emulated in https://gamepad-tester.com/. However, right after running the cell, if I maximize a game window, nothing happens.

How to make sure my code sends my instructions to the opened game? I am running the code in jupyter notebook.

import vgamepad as vg import time import math gamepad = vg.VX360Gamepad()

center_x = 0.5 # X-coordinate of the joystick center center_y = 0.5 # Y-coordinate of the joystick center radius = 0.4 # Radius of the circular motion speed = 6.0 # Speed of the circular motion (radians per second)

start_time = time.time() while time.time() - start_time < 10: elapsed_time = time.time() - start_time angle = elapsed_time speed x = center_x + radius math.cos(angle) y = center_y + radius math.sin(angle)' ` x_value = 2 (x - center_x) y_value = 2 * (y - center_y) gamepad.left_joystick_float(x_value_float=x_value, y_value_float=y_value) time.sleep(0.01) gamepad.update()

yannbouteiller commented 1 year ago

Hi, when you create a VX360Gamepad object, it is like connecting a gamepad to your PC. When your python script reaches the end, this object gets destroyed, and your PC thinks the gamepad is disconnected.

Probably you want the python script to be already running when you launch the game, because some games don't detect gamepads that are connected while they are running, and you want to make sure the script is still running after you maximize the window.

Closing as this doesn't seem to be a library issue, please feel free to continue the discussion here though.