pyInputStreaming/Client.py

46 lines
1.2 KiB
Python
Raw Normal View History

2020-06-02 18:10:07 -05:00
#!/usr/bin/python
import socket
import threading
import re
2020-06-02 22:11:32 -05:00
import pyxinput
from time import sleep
2020-06-02 18:10:07 -05:00
# Define server ip and port
2020-06-02 22:11:32 -05:00
ip = '192.168.122.1'
2020-06-02 18:10:07 -05:00
port = 2222
#Define globals
decodedServerData = ""
def recvData(ip, port):
global decodedServerData
# Connect to Server
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#client.setblocking(False)
client.connect((ip, port))
while True:
from_server = client.recv(4096)
#Decode Sever message
decodedServerData = from_server.decode()
2020-06-02 22:11:32 -05:00
print("Raw Data:", decodedServerData)
def virtualController():
MyVirtual = pyxinput.vController()
MyRead = pyxinput.rController(1)
print(MyRead.gamepad)
2020-06-02 18:10:07 -05:00
while True:
2020-06-02 22:11:32 -05:00
#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)
2020-06-02 18:10:07 -05:00
# Execute all functions as threads
if __name__ == "__main__":
#Create Threads
t1 = threading.Thread(target=recvData, args=(ip, port))
2020-06-02 22:11:32 -05:00
t2 = threading.Thread(target=virtualController, args=())
#t1.start()
2020-06-02 18:10:07 -05:00
t2.start()