jmtrevaskis

wiisync.au3

Nov 3rd, 2011
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 KB | None | 0 0
  1. ;wiisync - auto setup tool w00t
  2. ;written @ 1/11/11 - apocolpyse?
  3. ; by James Trevaskis http://metasplo.it
  4.  
  5. ;includes
  6. #include-once
  7. #include <GuiConstantsEx.au3>
  8. #include <Constants.au3>
  9. #include <array.au3>
  10. #include <GuiToolbar.au3>
  11. #include <WindowsConstants.au3>
  12.  
  13.  
  14. Opt('MustDeclareVars', 1)
  15.  
  16. ;message to user
  17. msgbox(0, "WiiSync Setup Wizard", "Please turn the ON/OFF switch to the ON position." & @LF & @LF & "If it is currently ON, please turn it off, wait 5 seconds, then turn it back on." & @LF & @LF & "Then click OK.")
  18.  
  19. ;block input from busy student hands
  20. blockinput(1)
  21. msgbox(0, "WiiSync Establishing Connection", "Please wait patiently while the touch interface is established..." & @LF & @LF & "I have kindly disabled your keyboard and mouse to prevent interference with the setup process.", 5)
  22.  
  23. ;killing open wiituio
  24. ProcessClose ( "WiiTUIO.exe" )
  25. Run("c:\wiimote\process.exe -k wiituio.exe", "")
  26. sleep(500)
  27.  
  28. ;refresh tray notification area
  29. _RefreshSystemTray(1000)
  30. sleep(500)
  31.  
  32. ;running wiituio
  33. run("c:\wiimote\wiituio.exe")
  34. sleep(6500)
  35.  
  36. ; popup WinTUIO window
  37. Global $hSysTray_Handle, $iSystray_ButtonNumber
  38. Global $sToolTipTitle = "[tool tip here]"
  39. $iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)
  40.  
  41. If $iSystray_ButtonNumber = 0 Then
  42. Global $hSysTray_Handle, $iSystray_ButtonNumber
  43. ;repeating the process twice as it doesnt always grab first time
  44. Global $sToolTipTitle = "[tool tip here]"
  45. $iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)
  46. If $iSystray_ButtonNumber = 0 Then
  47. msgbox(0, ".", "Connect failed, please rerun WiiSync...", 5)
  48. Exit
  49. Else
  50. Sleep(500)
  51. _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "left")
  52. EndIf
  53. Else
  54. Sleep(500)
  55. _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "left")
  56. EndIf
  57.  
  58. ;setting up WinTUIO
  59. sleep(3000)
  60. send("{tab}{tab}{tab}{+}")
  61. sleep(1000)
  62. send("{tab}{tab}{+}")
  63. sleep(1000)
  64. send("{tab}{tab}{enter}")
  65. sleep(2500)
  66.  
  67. ;make window disappear
  68. send("{LWIN}")
  69. sleep(100)
  70. send("{LWIN}")
  71.  
  72. ;unblock Input
  73. blockinput(0)
  74.  
  75. ;EOF
  76. msgbox(0, "WiiSync Complete", "Synchronization complete, if the touch interface fails, please re-run WiiSync.")
  77. Exit
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. ;#
  86. ;#FUNCTIONS
  87. ;#
  88.  
  89.  
  90. ; ===================================================================
  91. ; _RefreshSystemTray($nDealy = 1000)
  92. ;
  93. ; Removes any dead icons from the notification area.
  94. ; Parameters:
  95. ; $nDelay - IN/OPTIONAL - The delay to wait for the notification area to expand with Windows XP's
  96. ; "Hide Inactive Icons" feature (In milliseconds).
  97. ; Returns:
  98. ; Sets @error on failure:
  99. ; 1 - Tray couldn't be found.
  100. ; 2 - DllCall error.
  101. ; ===================================================================
  102. Func _RefreshSystemTray($nDelay = 1000)
  103. ; Save Opt settings
  104. Local $oldMatchMode = Opt("WinTitleMatchMode", 4)
  105. Local $oldChildMode = Opt("WinSearchChildren", 1)
  106. Local $error = 0
  107. Do; Pseudo loop
  108. Local $hWnd = WinGetHandle("classname=TrayNotifyWnd")
  109. If @error Then
  110. $error = 1
  111. ExitLoop
  112. EndIf
  113.  
  114. Local $hControl = ControlGetHandle($hWnd, "", "Button1")
  115.  
  116. ; We're on XP and the Hide Inactive Icons button is there, so expand it
  117. If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then
  118. ControlClick($hWnd, "", $hControl)
  119. Sleep($nDelay)
  120. EndIf
  121.  
  122. Local $posStart = MouseGetPos()
  123. Local $posWin = WinGetPos($hWnd)
  124.  
  125. Local $y = $posWin[1]
  126. While $y < $posWin[3] + $posWin[1]
  127. Local $x = $posWin[0]
  128. While $x < $posWin[2] + $posWin[0]
  129. DllCall("user32.dll", "int", "SetCursorPos", "int", $x, "int", $y)
  130. If @error Then
  131. $error = 2
  132. ExitLoop 3; Jump out of While/While/Do
  133. EndIf
  134. $x = $x + 8
  135. WEnd
  136. $y = $y + 8
  137. WEnd
  138. DllCall("user32.dll", "int", "SetCursorPos", "int", $posStart[0], "int", $posStart[1])
  139. ; We're on XP so we need to hide the inactive icons again.
  140. If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then
  141. ControlClick($hWnd, "", $hControl)
  142. EndIf
  143. Until 1
  144.  
  145. ; Restore Opt settings
  146. Opt("WinTitleMatchMode", $oldMatchMode)
  147. Opt("WinSearchChildren", $oldChildMode)
  148. SetError($error)
  149. EndFunc; _RefreshSystemTray()
  150.  
  151.  
  152.  
  153.  
  154. Func Get_Systray_Index($sToolTipTitle)
  155.  
  156. ; Find systray handle
  157. $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
  158. If @error Then
  159. ;MsgBox(16, "Error", "System tray not found")
  160. Exit
  161. EndIf
  162.  
  163. ; Get systray item count
  164. Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
  165. If $iSystray_ButCount = 0 Then
  166. ;MsgBox(16, "Error", "No items found in system tray")
  167. Exit
  168. EndIf
  169.  
  170. ; Look for wanted tooltip
  171. For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
  172. ;msgbox(0, ".", $hSysTray_Handle & @LF & $iSystray_ButtonNumber)
  173. ;global $testvar = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber)
  174. ;msgbox(0, "testvar", "button number: " & $iSystray_ButtonNumber & @LF & "testvar: " & $testvar)
  175. If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) = 1 Then ExitLoop
  176. Next
  177.  
  178. ;debug
  179. ;msgbox(0, ".", $iSystray_ButtonNumber)
  180.  
  181. If $iSystray_ButtonNumber = $iSystray_ButCount Then
  182. Return 0 ; Not found
  183. Else
  184. Return $iSystray_ButtonNumber ; Found
  185. EndIf
  186.  
  187. EndFunc
Add Comment
Please, Sign In to add comment