Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.16 KB | None | 0 0
  1. #SingleInstance force ; Force replacement of old instances
  2.  
  3. ; ACC Library (Required for Chrome Function)
  4. Acc_Init()
  5. {
  6. Static h
  7. If Not h
  8. h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
  9. }
  10. Acc_ObjectFromEvent(ByRef _idChild_, hWnd, idObject, idChild)
  11. {
  12. Acc_Init()
  13. If DllCall("oleacc\AccessibleObjectFromEvent", "Ptr", hWnd, "UInt", idObject, "UInt", idChild, "Ptr*", pacc, "Ptr", VarSetCapacity(varChild,8+2*A_PtrSize,0)*0+&varChild)=0
  14. Return ComObjEnwrap(9,pacc,1), _idChild_:=NumGet(varChild,8,"UInt")
  15. }
  16.  
  17. Acc_ObjectFromPoint(ByRef _idChild_ = "", x = "", y = "")
  18. {
  19. Acc_Init()
  20. If DllCall("oleacc\AccessibleObjectFromPoint", "Int64", x==""||y==""?0*DllCall("GetCursorPos","Int64*",pt)+pt:x&0xFFFFFFFF|y<<32, "Ptr*", pacc, "Ptr", VarSetCapacity(varChild,8+2*A_PtrSize,0)*0+&varChild)=0
  21. Return ComObjEnwrap(9,pacc,1), _idChild_:=NumGet(varChild,8,"UInt")
  22. }
  23.  
  24. Acc_ObjectFromWindow(hWnd, idObject = -4)
  25. {
  26. Acc_Init()
  27. If DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr", -VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0
  28. Return ComObjEnwrap(9,pacc,1)
  29. }
  30.  
  31. Acc_WindowFromObject(pacc)
  32. {
  33. If DllCall("oleacc\WindowFromAccessibleObject", "Ptr", IsObject(pacc)?ComObjValue(pacc):pacc, "Ptr*", hWnd)=0
  34. Return hWnd
  35. }
  36.  
  37. Acc_GetRoleText(nRole)
  38. {
  39. nSize := DllCall("oleacc\GetRoleText", "Uint", nRole, "Ptr", 0, "Uint", 0)
  40. VarSetCapacity(sRole, (A_IsUnicode?2:1)*nSize)
  41. DllCall("oleacc\GetRoleText", "Uint", nRole, "str", sRole, "Uint", nSize+1)
  42. Return sRole
  43. }
  44.  
  45. Acc_GetStateText(nState)
  46. {
  47. nSize := DllCall("oleacc\GetStateText", "Uint", nState, "Ptr", 0, "Uint", 0)
  48. VarSetCapacity(sState, (A_IsUnicode?2:1)*nSize)
  49. DllCall("oleacc\GetStateText", "Uint", nState, "str", sState, "Uint", nSize+1)
  50. Return sState
  51. }
  52.  
  53. Acc_SetWinEventHook(eventMin, eventMax, pCallback)
  54. {
  55. Return DllCall("SetWinEventHook", "Uint", eventMin, "Uint", eventMax, "Uint", 0, "Ptr", pCallback, "Uint", 0, "Uint", 0, "Uint", 0)
  56. }
  57.  
  58. Acc_UnhookWinEvent(hHook)
  59. {
  60. Return DllCall("UnhookWinEvent", "Ptr", hHook)
  61. }
  62. /* Win Events:
  63. pCallback := RegisterCallback("WinEventProc")
  64. WinEventProc(hHook, event, hWnd, idObject, idChild, eventThread, eventTime)
  65. {
  66. Critical
  67. Acc := Acc_ObjectFromEvent(_idChild_, hWnd, idObject, idChild)
  68. ; Code Here:
  69. }
  70. */
  71.  
  72. Acc_Role(Acc, ChildId=0) {
  73. try return ComObjType(Acc,"Name")="IAccessible"?Acc_GetRoleText(Acc.accRole(ChildId)):"invalid object"
  74. }
  75. Acc_State(Acc, ChildId=0) {
  76. try return ComObjType(Acc,"Name")="IAccessible"?Acc_GetStateText(Acc.accState(ChildId)):"invalid object"
  77. }
  78. Acc_Location(Acc, ChildId=0, byref Position="") {
  79. try Acc.accLocation(ComObj(0x4003,&x:=0), ComObj(0x4003,&y:=0), ComObj(0x4003,&w:=0), ComObj(0x4003,&h:=0), ChildId)
  80. catch
  81. return
  82. Position := "x" NumGet(x,0,"int") " y" NumGet(y,0,"int") " w" NumGet(w,0,"int") " h" NumGet(h,0,"int")
  83. return {x:NumGet(x,0,"int"), y:NumGet(y,0,"int"), w:NumGet(w,0,"int"), h:NumGet(h,0,"int")}
  84. }
  85. Acc_Parent(Acc) {
  86. try parent:=Acc.accParent
  87. return parent?Acc_Query(parent):
  88. }
  89. Acc_Child(Acc, ChildId=0) {
  90. try child:=Acc.accChild(ChildId)
  91. return child?Acc_Query(child):
  92. }
  93. Acc_Query(Acc) {
  94. try return ComObj(9, ComObjQuery(Acc,"{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
  95. }
  96. Acc_Error(p="") {
  97. static setting:=0
  98. return p=""?setting:setting:=p
  99. }
  100. Acc_Children(Acc) {
  101. if ComObjType(Acc,"Name") != "IAccessible"
  102. ErrorLevel := "Invalid IAccessible Object"
  103. else {
  104. Acc_Init(), cChildren:=Acc.accChildCount, Children:=[]
  105. if DllCall("oleacc\AccessibleChildren", "Ptr",ComObjValue(Acc), "Int",0, "Int",cChildren, "Ptr",VarSetCapacity(varChildren,cChildren*(8+2*A_PtrSize),0)*0+&varChildren, "Int*",cChildren)=0 {
  106. Loop %cChildren%
  107. i:=(A_Index-1)*(A_PtrSize*2+8)+8, child:=NumGet(varChildren,i), Children.Insert(NumGet(varChildren,i-8)=9?Acc_Query(child):child), NumGet(varChildren,i-8)=9?ObjRelease(child):
  108. return Children.MaxIndex()?Children:
  109. } else
  110. ErrorLevel := "AccessibleChildren DllCall Failed"
  111. }
  112. if Acc_Error()
  113. throw Exception(ErrorLevel,-1)
  114. }
  115. Acc_ChildrenByRole(Acc, Role) {
  116. if ComObjType(Acc,"Name")!="IAccessible"
  117. ErrorLevel := "Invalid IAccessible Object"
  118. else {
  119. Acc_Init(), cChildren:=Acc.accChildCount, Children:=[]
  120. if DllCall("oleacc\AccessibleChildren", "Ptr",ComObjValue(Acc), "Int",0, "Int",cChildren, "Ptr",VarSetCapacity(varChildren,cChildren*(8+2*A_PtrSize),0)*0+&varChildren, "Int*",cChildren)=0 {
  121. Loop %cChildren% {
  122. i:=(A_Index-1)*(A_PtrSize*2+8)+8, child:=NumGet(varChildren,i)
  123. if NumGet(varChildren,i-8)=9
  124. AccChild:=Acc_Query(child), ObjRelease(child), Acc_Role(AccChild)=Role?Children.Insert(AccChild):
  125. else
  126. Acc_Role(Acc, child)=Role?Children.Insert(child):
  127. }
  128. return Children.MaxIndex()?Children:, ErrorLevel:=0
  129. } else
  130. ErrorLevel := "AccessibleChildren DllCall Failed"
  131. }
  132. if Acc_Error()
  133. throw Exception(ErrorLevel,-1)
  134. }
  135. Acc_Get(Cmd, ChildPath="", ChildID=0, WinTitle="", WinText="", ExcludeTitle="", ExcludeText="") {
  136. static properties := {Action:"DefaultAction", DoAction:"DoDefaultAction", Keyboard:"KeyboardShortcut"}
  137. AccObj := IsObject(WinTitle)? WinTitle
  138. : Acc_ObjectFromWindow( WinExist(WinTitle, WinText, ExcludeTitle, ExcludeText), 0 )
  139. if ComObjType(AccObj, "Name") != "IAccessible"
  140. ErrorLevel := "Could not access an IAccessible Object"
  141. else {
  142. StringReplace, ChildPath, ChildPath, _, %A_Space%, All
  143. StringReplace, ChildPath, ChildPath, `,, ., All
  144. AccError:=Acc_Error(), Acc_Error(true)
  145. Loop Parse, ChildPath, ., %A_Space%
  146. try {
  147. if A_LoopField is digit
  148. Children:=Acc_Children(AccObj), m2:=A_LoopField ; mimic "m2" output in else-statement
  149. else
  150. RegExMatch(A_LoopField, "(\D*)(\d*)", m), Children:=Acc_ChildrenByRole(AccObj, m1), m2:=(m2?m2:1)
  151. if Not Children.HasKey(m2)
  152. throw
  153. AccObj := Children[m2]
  154. } catch {
  155. ErrorLevel:="Cannot access ChildPath Item #" A_Index " -> " A_LoopField, Acc_Error(AccError)
  156. if Acc_Error()
  157. throw Exception("Cannot access ChildPath Item", -1, "Item #" A_Index " -> " A_LoopField)
  158. return
  159. }
  160. Acc_Error(AccError)
  161. StringReplace, Cmd, Cmd, %A_Space%, , All
  162. properties.HasKey(Cmd)? Cmd:=properties[Cmd]:
  163. try {
  164. if (Cmd = "Location")
  165. AccObj.accLocation(ComObj(0x4003,&x:=0), ComObj(0x4003,&y:=0), ComObj(0x4003,&w:=0), ComObj(0x4003,&h:=0), ChildId)
  166. , ret_val := "x" NumGet(x,0,"int") " y" NumGet(y,0,"int") " w" NumGet(w,0,"int") " h" NumGet(h,0,"int")
  167. else if (Cmd = "Object")
  168. ret_val := AccObj
  169. else if Cmd in Role,State
  170. ret_val := Acc_%Cmd%(AccObj, ChildID+0)
  171. else if Cmd in ChildCount,Selection,Focus
  172. ret_val := AccObj["acc" Cmd]
  173. else
  174. ret_val := AccObj["acc" Cmd](ChildID+0)
  175. } catch {
  176. ErrorLevel := """" Cmd """ Cmd Not Implemented"
  177. if Acc_Error()
  178. throw Exception("Cmd Not Implemented", -1, Cmd)
  179. return
  180. }
  181. return ret_val, ErrorLevel:=0
  182. }
  183. if Acc_Error()
  184. throw Exception(ErrorLevel,-1)
  185. }
  186.  
  187. ; Function to grab active chrome tab
  188. ChromeActivate(SearchText, AccPath_TabList := "4,1,2,2,2") {
  189. TabList := Acc_Get("Object", AccPath_TabList, 0, "ahk_class Chrome_WidgetWin_1")
  190. Loop, % Acc_Children(TabList).MaxIndex() {
  191. _tab := Acc_Child(TabList, A_Index)
  192. tabTitle := _tab.accName(0)
  193. if InStr(tabTitle, SearchText) {
  194. _tab.accDoDefaultAction(0)
  195. return true
  196. }
  197. }
  198. }
  199.  
  200. ^!x:: ; Control+Alt+X hotkey
  201. if ChromeActivate("solarmovie") {
  202. WinActivate, ahk_class Chrome_WidgetWin_1
  203. Sleep, 100
  204. Goto, ImageSearch
  205. }
  206.  
  207. /*
  208. ; Window Activation / Tab Activation without ACC Library
  209. WinActivate, ahk_class Chrome_WidgetWin_1
  210. WinWaitActive, ahk_class Chrome_WidgetWin_1
  211. WinGetTitle, CurrentWindowTitle, ahk_class Chrome_WidgetWin_1
  212. Sleep, 2000 ; Appears to be issue where title is not being recognized, mouse movement corrects
  213. If CurrentWindowTitle contains solarmovie
  214. Goto, ImageSearch
  215. ; else
  216. Loop
  217. {
  218. Send, ^{Tab}
  219. Sleep, 50
  220. WinGetTitle, CurrentWindowTitle, ahk_class Chrome_WidgetWin_1
  221. If CurrentWindowTitle not contains solarmovie
  222. Continue
  223. ; else
  224. break
  225. }
  226. Goto, ImageSearch
  227. */
  228.  
  229. Return
  230. ImageSearch:
  231. CoordMode Pixel ; Interprets the coordinates below as relative to the screen rather than the active window.
  232. CoordMode Mouse ; Interprets the coordinates below as relative to the screen rather than the active window, for the mouse.
  233. ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\Users\Dom\Desktop\NextVideoScript\OnAir.png
  234. if ErrorLevel = 2
  235. MsgBox Could not conduct the search.
  236. else if ErrorLevel = 1
  237. MsgBox Icon could not be found on the screen.
  238. else
  239. NextVideo:
  240. MouseMove, %FoundX%, % FoundY - 40
  241. MouseGetPos, Mx, My
  242. if (Mx = 1690) and (My = 255) {
  243. Msgbox, Fuck
  244. Return
  245. }
  246. else
  247. MouseClick, left
  248. MouseGetPos, Mx, My
  249. MouseMove, % Mx - 950, % My - 20
  250. Sleep, 2000
  251. MouseClick, left
  252. MouseClick, left
  253. Send F
  254. Return
  255. /*
  256. Next Episode 1.1
  257.  
  258. To Do:
  259. Figure out how to solve requirement to scroll when episode is at top of list
  260.  
  261. Change log:
  262.  
  263. 1.0:
  264. Initial script creation
  265.  
  266. 1.1:
  267. Added ACC library
  268. Added activate Chrome tab function (depends on ACC library)
  269.  
  270. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement