Advertisement
SamGauths

PC Controller (Client App)

Feb 28th, 2019
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.14 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.108" ; 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.  
  24.     ; Assign a Local variable the socket and connect to a listening socket with the IP Address and Port specified.
  25.     Local $iSocket = UDPOpen($sIPAddress, $iPort)
  26.     Local $defaultKeyRepeatTime = 50
  27.  
  28.     While 1
  29.  
  30.  
  31.         If _IsPressed("68", $hDLL) Then  ;up key
  32.             While _IsPressed("68", $hDLL)
  33.                 Sleep($defaultKeyRepeatTime)
  34.                 UDPSend($iSocket, StringToBinary("up")) ;move mouse up
  35.             WEnd
  36.         EndIf
  37.  
  38.         If _IsPressed("62", $hDLL) Then  ;down key
  39.             While _IsPressed("62", $hDLL)
  40.                 Sleep($defaultKeyRepeatTime)
  41.                 UDPSend($iSocket, StringToBinary("dn")) ;move mouse down
  42.             WEnd
  43.         EndIf
  44.  
  45.         If _IsPressed("64", $hDLL) Then  ;left key
  46.             While _IsPressed("64", $hDLL)
  47.                 Sleep($defaultKeyRepeatTime)
  48.                 UDPSend($iSocket, StringToBinary("le")) ;move mouse left
  49.             WEnd
  50.         EndIf
  51.  
  52.         If _IsPressed("66", $hDLL) Then  ;right key
  53.             While _IsPressed("66", $hDLL)
  54.                 Sleep($defaultKeyRepeatTime)
  55.                 UDPSend($iSocket, StringToBinary("ri")) ;move mouse right
  56.             WEnd
  57.         EndIf
  58.  
  59.         If _IsPressed("67", $hDLL) Then  ;space key
  60.             While _IsPressed("67", $hDLL)
  61.                 Sleep($defaultKeyRepeatTime)
  62.             WEnd
  63.             UDPSend($iSocket, StringToBinary("dc")) ;mouse double click
  64.         EndIf
  65.  
  66.         If _IsPressed("69", $hDLL) Then  ;space key
  67.             While _IsPressed("69", $hDLL)
  68.                 Sleep($defaultKeyRepeatTime)
  69.             WEnd
  70.             UDPSend($iSocket, StringToBinary("rc")) ;mouse double click
  71.         EndIf
  72.  
  73.     Sleep(50)
  74.     WEnd
  75.     ; Close the socket.
  76.     UDPCloseSocket($iSocket)
  77.  
  78.     WEnd
  79.     #EndRegion GUI
  80. EndFunc   ;==>Example
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement