Advertisement
Guest User

leaning.au3

a guest
Jul 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.88 KB | None | 0 0
  1. #include <array.au3>
  2. #include <file.au3>
  3. OnAutoItExitRegister("CLEANUP")
  4. Opt("SendKeyDelay", 0)
  5. Opt("SendKeyDownDelay", 0)
  6. Global $qdown = false, $edown = False
  7. Global $stream = Run(@ComSpec & " /c c:\androidsdk\platform-tools\", @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD)
  8.  
  9. ; The purpose of this initial loop is just to wait until adb.exe begins to send XSENSOR messages
  10. while 1
  11.     $lines = StdoutRead($stream)
  12.     if StringInStr($lines, "XSENSOR") Then
  13.         sleep(50)
  14.         ExitLoop
  15.     EndIf
  16. WEnd
  17.  
  18. ; Main loop
  19. while 1
  20.     $lines = StdoutRead($stream)
  21.     local $str = StringRight($lines, 85)
  22.     Local $Match = StringRegExp($lines, "[,]HIGH[,]([^,]+)[,]([^,]+)[,]([\d.-]+)$", 3)
  23.     If IsArray($Match) Then
  24.         ; I have it checking for either PUBG or for Notepad, that way you can open notepad to test. It should type Q's and E's as you rotate your phone.
  25.         if ( WinActive("[TITLE:PLAYERUNKNOWN'S BATTLEGROUNDS;CLASS:UnrealWindow]") or WinActive("Untitled - Notepad") ) Then
  26.             $x = Number($Match[0])
  27.             ; Change -1 and 1 below to adjust the range which is required for Q or E to be released when you stop leaning.
  28.             if ($x > -1) and $edown Then
  29.                 $edown = False
  30.                 Send("{e Up}")
  31.                 sleep(20)
  32.             ElseIf ($x < 1) and $qdown Then
  33.                 $qdown = False
  34.                 Send("{q Up}")
  35.                 sleep(20)
  36.             EndIf
  37.  
  38.             ; Change -3 and 3 below to adjust the threshold required to trigger pressing down Q and E
  39.             if ($x > 3) and not $qdown Then
  40.                 $qdown = True
  41.                 Send("{q Down}")
  42.             ElseIf ( $x < -3) and not $edown Then
  43.                 $edown = True
  44.                 Send("{e Down}")
  45.             EndIf
  46.         EndIf
  47.     EndIf
  48.     sleep(20) ;you can try removing this 20ms sleep to experiment with responsiveness, it is here for CPU usage considerations
  49. WEnd
  50.  
  51. Func CLEANUP()  ;adb.exe has troulbe shutting down sometimes, this function is called when you exit this script.
  52.     while ProcessExists("adb.exe")
  53.         ProcessClose("adb.exe")
  54.     WEnd
  55.     Exit
  56. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement