SamGauths

PC Controller (Server App)

Feb 28th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.33 KB | None | 0 0
  1. #include <GUIConstantsEx.au3>
  2. #include <MsgBoxConstants.au3>
  3. #include <Misc.au3>
  4.  
  5. Local $hDLL = DllOpen("user32.dll")
  6.  
  7. ; Start First clicking on "1. Server"
  8. ; Then start a second instance of the script selecting "2. Client"
  9.  
  10. Example()
  11.  
  12. Func Example()
  13.     UDPStartup() ; Start the UDP service.
  14.  
  15.     ; Register OnAutoItExit to be called when the script is closed.
  16.     OnAutoItExitRegister("OnAutoItExit")
  17.  
  18.     ; Assign Local variables the loopback IP Address and the Port.
  19.     Local $sIPAddress = "192.168.1.92" ; This IP Address only works for testing on your own computer.
  20.     Local $iPort = 65532 ; Port used for the connection.
  21.  
  22.     While 1
  23.     ; Assign a Local variable the socket and bind to the IP Address and Port specified.
  24.     Local $iSocket = UDPBind($sIPAddress, $iPort)
  25.  
  26.     ; Assign a Local variable to store the data received.
  27.     Local $sReceived = ""
  28.     Local $mousePosX = 0
  29.     Local $mousePosY = 0
  30.     Local $moveGap = 20
  31.     Local $mouseSpeed = 2
  32.  
  33.     Do
  34.         ; We are waiting for the string "toto" OR "tata" (example script UDPSend): 4 bytes length.
  35.         $sReceived = UDPRecv($iSocket, 2)
  36.     Until $sReceived <> ""
  37.  
  38.     ; Notes: If you don't know how much length will be the data,
  39.     ; use e.g: 2048 for maxlen parameter and call the function until the it returns nothing/error.
  40.     While 1
  41.         $sReceived = UDPRecv($iSocket, 2) ;we're waiting for the string "tata" OR "toto" (example script TCPRecv): 4 bytes length.
  42.         If $sReceived = "ta" Then
  43.             MouseMove(700, 700, 20)
  44.         EndIf
  45.  
  46.         If $sReceived = "up" Then
  47.             $mousePosY = $mousePosY - $moveGap
  48.             MouseMove($mousePosX, $mousePosY, $mouseSpeed)
  49.         EndIf
  50.  
  51.         If $sReceived = "dn" Then
  52.             $mousePosY = $mousePosY + $moveGap
  53.             MouseMove($mousePosX, $mousePosY, $mouseSpeed)
  54.         EndIf
  55.  
  56.         If $sReceived = "le" Then
  57.             $mousePosX = $mousePosX - $moveGap
  58.             MouseMove($mousePosX, $mousePosY, $mouseSpeed)
  59.         EndIf
  60.  
  61.         If $sReceived = "ri" Then
  62.             $mousePosX = $mousePosX + $moveGap
  63.             MouseMove($mousePosX, $mousePosY, $mouseSpeed)
  64.         EndIf
  65.  
  66.         If $sReceived = "dc" Then
  67.             MouseClick("left", $mousePosX, $mousePosY, 2) ;mouse double click
  68.         EndIf
  69.  
  70.         If $sReceived = "rc" Then
  71.             MouseClick("right", $mousePosX, $mousePosY, 1) ;mouse double click
  72.         EndIf
  73.     WEnd
  74.  
  75.     ; Close the socket.
  76.     UDPCloseSocket($iSocket)
  77.     WEnd
  78.     #EndRegion GUI
  79. EndFunc   ;==>Example
Add Comment
Please, Sign In to add comment