From 9afdf5a4d9c64239c93d94255c08a94006170fe9 Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Tue, 2 Jun 2020 22:11:32 -0500 Subject: [PATCH] added xInput library to client --- Client.py | 30 +++++++++++++++++++++--------- Server.py | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Client.py b/Client.py index d7791c4..861e4e5 100644 --- a/Client.py +++ b/Client.py @@ -2,8 +2,10 @@ import socket import threading import re +import pyxinput +from time import sleep # Define server ip and port -ip = '127.0.0.1' +ip = '192.168.122.1' port = 2222 #Define globals decodedServerData = "" @@ -17,17 +19,27 @@ def recvData(ip, port): from_server = client.recv(4096) #Decode Sever message decodedServerData = from_server.decode() - -def printData(): + print("Raw Data:", decodedServerData) +def virtualController(): + MyVirtual = pyxinput.vController() + MyRead = pyxinput.rController(1) + print(MyRead.gamepad) + while True: - global decodedServerData - #print("Raw Data:", decodedServerData) - #print('\n'+":O", end="\r", flush=True) - + #global decodedServerData + # Init virtual XInput Controller + #print(MyRead.gamepad) + MyVirtual.set_value('BtnA', 1) + print(MyRead.buttons) + sleep(3) + #print(MyRead.gamepad) + MyVirtual.set_value('BtnA', 0) + print(MyRead.buttons) + sleep(3) # Execute all functions as threads if __name__ == "__main__": #Create Threads t1 = threading.Thread(target=recvData, args=(ip, port)) - t2 = threading.Thread(target=printData, args=()) -t1.start() + t2 = threading.Thread(target=virtualController, args=()) +#t1.start() t2.start() diff --git a/Server.py b/Server.py index fb367a7..65ac608 100644 --- a/Server.py +++ b/Server.py @@ -6,7 +6,7 @@ import threading import socket from termcolor import colored # Define ip/port to use -ip = "127.0.0.1" +ip = "192.168.122.1" port = 2222 # Show available gamepads print("Gamepads available:")