PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/ahk_scripts/DoOver.ahk

http://github.com/jixiuf/my_autohotkey_scripts
AutoHotKey | 485 lines | 434 code | 44 blank | 7 comment | 0 complexity | 547a1e345df256fb4439760355096b71 MD5 | raw file
Possible License(s): GPL-3.0
  1. ;DoOver.ahk
  2. ; Record and playback keyboard and mouse actions.
  3. ; Press Ctrl-F12 to start and stop recording.
  4. ; Press Ctrl-F5 to playback.
  5. ;Skrommel @2005 www.donationcoders.com/skrommel
  6. #NoTrayIcon
  7. #SingleInstance,Force
  8. SetBatchLines,-1
  9. AutoTrim,Off
  10. CoordMode,Mouse,Relative
  11. applicationname=DoOver
  12. modifiers=LCTRL,RCTRL,LALT,RALT,LSHIFT,RSHIFT,LWIN,RWIN,LButton,RButton,MButton,XButton1,XButton2
  13. recording=0
  14. playing=0
  15. Gosub,READINI
  16. Gosub,TRAYMENU
  17. SetTimer,CURRENTWIN,500
  18. Return
  19. CURRENTWIN:
  20. WinGet,currentid,ID,A
  21. WinGetClass,class,ahk_id %currentid%
  22. If currentid=
  23. currentid=%oldcurrentid%
  24. If class=Shell_TrayWnd
  25. currentid=%oldcurrentid%
  26. If currentid=AutoHotkey
  27. currentid=%oldcurrentid%
  28. oldcurrentid=%currentid%
  29. Return
  30. MACROREC:
  31. If recording=0
  32. {
  33. GetKeyState,state,LShift,P
  34. If state=d
  35. Loop
  36. {
  37. GetKeyState,state,LShift,P
  38. If state=U
  39. Break
  40. }
  41. GetKeyState,state,LCtrl,P
  42. If state=d
  43. Loop
  44. {
  45. GetKeyState,state,LCtrl,P
  46. If state=U
  47. Break
  48. }
  49. GetKeyState,state,LAlt,P
  50. If state=d
  51. Loop
  52. {
  53. GetKeyState,state,LAlt,P
  54. If state=U
  55. Break
  56. }
  57. GetKeyState,state,LWin,P
  58. If state=d
  59. Loop
  60. {
  61. GetKeyState,state,LWin,P
  62. If state=U
  63. Break
  64. }
  65. recording=1
  66. ToolTip,Recording...
  67. Gosub,RECORD
  68. ToolTip,Recording finished
  69. IniWrite,%keys%,DoOver.ini,Settings,macro
  70. Loop
  71. {
  72. GetKeyState,state,LCtrl,P
  73. If state=U
  74. Break
  75. }
  76. Sleep,1000
  77. ToolTip,
  78. recording=0
  79. }
  80. Else
  81. recording=0
  82. Return
  83. MACROPLAY:
  84. If playing=0
  85. {
  86. GetKeyState,state,LShift,P
  87. If state=d
  88. Loop
  89. {
  90. GetKeyState,state,LShift,P
  91. If state=U
  92. Break
  93. }
  94. GetKeyState,state,LCtrl,P
  95. If state=d
  96. Loop
  97. {
  98. GetKeyState,state,LCtrl,P
  99. If state=U
  100. Break
  101. }
  102. GetKeyState,state,LAlt,P
  103. If state=d
  104. Loop
  105. {
  106. GetKeyState,state,LAlt,P
  107. If state=U
  108. Break
  109. }
  110. GetKeyState,state,LWin,P
  111. If state=d
  112. Loop
  113. {
  114. GetKeyState,state,LWin,P
  115. If state=U
  116. Break
  117. }
  118. playing=1
  119. ToolTip,Playback...
  120. IniRead,macro,DoOver.ini,Settings,macro
  121. If movemouseafter=1
  122. {
  123. CoordMode,Mouse,Screen
  124. MouseGetPos,origx,origy
  125. CoordMode,Mouse,Relative
  126. }
  127. Gosub,PLAYBACK
  128. If movemouseafter=1
  129. {
  130. CoordMode,Mouse,Screen
  131. MouseMove,%origx%,%origy%,0
  132. CoordMode,Mouse,Relative
  133. }
  134. ToolTip,
  135. playing=0
  136. }
  137. Return
  138. PLAYBACK:
  139. id=
  140. Loop
  141. {
  142. GetKeyState,state,Esc,P
  143. If state=d
  144. Break
  145. StringGetPos,pos1,macro,{MouseClick
  146. StringGetPos,pos2,macro,{Window
  147. If pos1=-1
  148. If pos2=-1
  149. {
  150. Send,%macro%
  151. Break
  152. }
  153. If pos2>-1
  154. If pos2<%pos1%
  155. Goto,WINDOW
  156. MOUSE:
  157. StringGetPos,pos1,macro,{MouseClick
  158. If pos1=-1
  159. Goto,WINDOW
  160. StringGetPos,pos2,macro,},,%pos1%
  161. StringLeft,playback,macro,%pos1%
  162. StringTrimLeft,macro,macro,%pos1%
  163. pos2-=%pos1%
  164. StringLeft,mouse,macro,%pos2%
  165. pos2+=1
  166. StringTrimLeft,macro,macro,%pos2%
  167. Send,%playback%
  168. StringSplit,mouse_,mouse,`,
  169. MouseClick,%mouse_2%,%mouse_3%,%mouse_4%,%mouse_5%,%mouse_6%,%mouse_7%
  170. Continue
  171. WINDOW:
  172. StringGetPos,pos1,macro,{Window
  173. If pos1=-1
  174. Continue
  175. StringGetPos,pos2,macro,},,%pos1%
  176. StringLeft,playback,macro,%pos1%
  177. StringTrimLeft,macro,macro,%pos1%
  178. pos2-=%pos1%
  179. StringLeft,title,macro,%pos2%
  180. pos2+=1
  181. StringTrimLeft,macro,macro,%pos2%
  182. Send,%playback%
  183. StringSplit,title_,title,`,
  184. WinWait,%title_2%,,2
  185. WinActivate,%title_2%
  186. WinWaitActive,%title_2%,,2
  187. ; WinWaitNotActive,ahk_id %id%,,2
  188. ; WinGet,id,ID,A
  189. }
  190. Return
  191. RECORD:
  192. SetTimer,MODIFIERS,50
  193. oldid=
  194. keys=
  195. Loop
  196. {
  197. Input,key,M B C V I L1 T1,{BackSpace}{Space}{WheelDown}{WheelUp}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{F13}{F14}{F15}{F16}{F17}{F18}{F19}{F20}{F21}{F22}{F23}{F24}{ENTER}{ESCAPE}{TAB}{DELETE}{INSERT}{UP}{DOWN}{LEFT}{RIGHT}{HOME}{END}{PGUP}{PGDN}{CapsLock}{ScrollLock}{NumLock}{APPSKEY}{SLEEP}{Numpad0}{Numpad0}{Numpad1}{Numpad2}{Numpad3}{Numpad4}{Numpad5}{Numpad6}{Numpad7}{Numpad8}{Numpad9}{NumpadDot}{NumpadEnter}{NumpadMult}{NumpadDiv}{NumpadAdd}{NumpadSub}{NumpadDel}{NumpadIns}{NumpadClear}{NumpadUp}{NumpadDown}{NumpadLeft}{NumpadRight}{NumpadHome}{NumpadEnd}{NumpadPgUp}{NumpadPgDn}{BROWSER_BACK}{BROWSER_FORWARD}{BROWSER_REFRESH}{BROWSER_STOP}{BROWSER_SEARCH}{BROWSER_FAVORITES}{BROWSER_HOME}{VOLUME_MUTE}{VOLUME_DOWN}{VOLUME_UP}{MEDIA_NEXT}{MEDIA_PREV}{MEDIA_STOP}{MEDIA_PLAY_PAUSE}{LAUNCH_MAIL}{LAUNCH_MEDIA}{LAUNCH_APP1}{LAUNCH_APP2}{PRINTSCREEN}{CTRLBREAK}{PAUSE}
  198. endkey=%ErrorLevel%
  199. WinGet,id,ID,A
  200. If id<>%oldid%
  201. {
  202. WinGetTitle,title,ahk_id %id%
  203. If title<>
  204. If title<>Program Manager
  205. keys=%keys%{Window,%title%}
  206. oldid=%id%
  207. }
  208. IfInString,endkey,EndKey:
  209. {
  210. StringTrimLeft,key,endkey,7
  211. key={%key%}
  212. }
  213. keys=%keys%%key%
  214. StringReplace,endrecord,record,},%A_Space%Down}
  215. IfInString,keys,%endrecord%
  216. {
  217. StringLen,length,endrecord
  218. StringTrimRight,keys,keys,%length%
  219. recording=0
  220. }
  221. If recording=0
  222. {
  223. SetTimer,MODIFIERS,Off
  224. Break
  225. }
  226. }
  227. Return
  228. MODIFIERS:
  229. Loop,Parse,modifiers,`,
  230. {
  231. GetKeyState,state,%A_LoopField%,P
  232. If (state="d" And state%A_Index%="")
  233. {
  234. state%A_Index%=d
  235. IfInString,A_LoopField,Button
  236. {
  237. StringReplace,button,A_LoopField,Button,
  238. WinGet,id,ID,A
  239. If id<>%oldid%
  240. {
  241. WinGetTitle,title,ahk_id %id%
  242. If title<>
  243. keys=%keys%{Window,%title%}
  244. oldid=%id%
  245. }
  246. WinGet,idd,ID,A
  247. MouseGetPos,xd,yd
  248. CoordMode,Mouse,Screen
  249. MouseGetPos,sdx,sdy
  250. CoordMode,Mouse,Relative
  251. keys=%keys%{MouseClick,%button%,%xd%,%yd%,1,0,D}
  252. }
  253. Else
  254. keys=%keys%{%A_LoopField% Down}
  255. }
  256. GetKeyState,state,%A_LoopField%,P
  257. If (state="u" And state%A_Index%="d")
  258. {
  259. IfInString,A_LoopField,Button
  260. {
  261. StringReplace,button,A_LoopField,Button,
  262. WinGet,idu,ID,A
  263. MouseGetPos,xu,yu
  264. CoordMode,Mouse,Screen
  265. MouseGetPos,sux,suy
  266. CoordMode,Mouse,Relative
  267. If(idd<>idu)
  268. {
  269. xd:=xd+sux-sdx
  270. yd:=yd+suy-sdy
  271. keys=%keys%{MouseClick,%button%,%xd%,%yd%,1,0,U}
  272. }
  273. Else
  274. keys=%keys%{MouseClick,%button%,%xu%,%yu%,1,0,U}
  275. }
  276. Else
  277. keys=%keys%{%A_LoopField% Up}
  278. state%A_Index%=
  279. }
  280. }
  281. If keys={LShift Up}
  282. keys=
  283. If keys={LCtrl Up}
  284. keys=
  285. If keys={LAlt Up}
  286. keys=
  287. If keys={LWin Up}
  288. keys=
  289. StringRight,tooltip,keys,100
  290. ToolTip,%tooltip%
  291. Return
  292. TRAYMENU:
  293. Menu,Tray,NoStandard
  294. Menu,Tray,DeleteAll
  295. Menu,Tray,Add,DoOver,TRAYPLAYBACK
  296. Menu,Tray,Add,
  297. Menu,Tray,Add,&Playback,TRAYPLAYBACK
  298. Menu,Tray,Add,&Record,TRAYRECORD
  299. Menu,Tray,Add,
  300. Menu,Tray,Add,&Settings...,SETTINGS
  301. Menu,Tray,Add,R&eload settings,RELOAD
  302. Menu,Tray,Add,
  303. Menu,Tray,Add,&About...,ABOUT
  304. Menu,Tray,Add,E&xit,EXIT
  305. Menu,Tray,Default,DoOVer
  306. Return
  307. TRAYPLAYBACK:
  308. WinActivate,ahk_id %currentid%
  309. WinWaitActive,ahk_id %currentid%,,2
  310. Gosub,MACROPLAY
  311. Return
  312. TRAYRECORD:
  313. WinActivate,ahk_id %currentid%
  314. WinWaitActive,ahk_id %currentid%,,2
  315. Gosub,MACROREC
  316. Return
  317. SETTINGS:
  318. Gosub,READINI
  319. Run,DoOver.ini
  320. Return
  321. RELOAD:
  322. Reload
  323. READINI:
  324. IfNotExist,DoOver.ini
  325. {
  326. ini=;DoOver.ini
  327. ini=%ini%`n;[Settings]
  328. ini=%ini%`n;record={LCtrl}{F12} `;hotkey to start and stop recording {LShift}{LCtrl}{LAlt}{LWin}{F1}...123...ABC...
  329. ini=%ini%`n;playback={LCtrl}{F5} `;hotkey to start playback
  330. ini=%ini%`n;keydelay=10 `;ms to wait after sending a keypress
  331. ini=%ini%`n;windelay=100 `;ms to wait after activating a window
  332. ini=%ini%`n;movemouseafter=1 `;move the mouse to original pos after playback 1=yes 0=no
  333. ini=%ini%`n
  334. ini=%ini%`n[Settings]
  335. ini=%ini%`nrecord={LCtrl}{F12}
  336. ini=%ini%`nplayback={LCtrl}{F5}
  337. ini=%ini%`nkeydelay=10
  338. ini=%ini%`nwindelay=100
  339. ini=%ini%`nmovemouseafter=1
  340. ini=%ini%`nmacro=
  341. FileAppend,%ini%,DoOver.ini
  342. ini=
  343. }
  344. IniRead,record,DoOver.ini,Settings,record
  345. hkrecord=%record%
  346. StringReplace,hkrecord,hkrecord,{LCtrl},^
  347. StringReplace,hkrecord,hkrecord,{RCtrl},^
  348. StringReplace,hkrecord,hkrecord,{LShift},+
  349. StringReplace,hkrecord,hkrecord,{RShift},+
  350. StringReplace,hkrecord,hkrecord,{LAlt},!
  351. StringReplace,hkrecord,hkrecord,{RAlt},!
  352. StringReplace,hkrecord,hkrecord,{LWin},#
  353. StringReplace,hkrecord,hkrecord,{RWin},#
  354. StringReplace,hkrecord,hkrecord,{,
  355. StringReplace,hkrecord,hkrecord,},
  356. Hotkey,%hkrecord%,MACROREC
  357. IniRead,playback,DoOver.ini,Settings,playback
  358. hkplayback=%playback%
  359. StringReplace,hkplayback,hkplayback,{LCtrl},^
  360. StringReplace,hkplayback,hkplayback,{RCtrl},^
  361. StringReplace,hkplayback,hkplayback,{LShift},+
  362. StringReplace,hkplayback,hkplayback,{RShift},+
  363. StringReplace,hkplayback,hkplayback,{LAlt},!
  364. StringReplace,hkplayback,hkplayback,{RAlt},!
  365. StringReplace,hkplayback,hkplayback,{LWin},#
  366. StringReplace,hkplayback,hkplayback,{RWin},#
  367. StringReplace,hkplayback,hkplayback,{,
  368. StringReplace,hkplayback,hkplayback,},
  369. IniRead,keydelay,DoOver.ini,Settings,keydelay
  370. IniRead,windelay,DoOver.ini,Settings,windelay
  371. Hotkey,%hkplayback%,MACROPLAY
  372. SetKeyDelay,%keydelay%
  373. SetWinDelay,%windelay%
  374. IniRead,movemouseafter,DoOver.ini,Settings,movemouseafter
  375. Return
  376. ABOUT:
  377. Gui,99:Destroy
  378. Gui,99:Margin,20,20
  379. Gui,99:Add,Picture,xm Icon1,%applicationname%.exe
  380. Gui,99:Font,Bold
  381. Gui,99:Add,Text,x+10 yp+10,%applicationname% v1.0
  382. Gui,99:Font
  383. Gui,99:Add,Text,y+10,Record and playback keyboard and mouse actions.
  384. Gui,99:Add,Text,y+10,- Press %record% to start and stop recording.
  385. Gui,99:Add,Text,y+10,- Press %playback% to playback.
  386. Gui,99:Add,Text,y+10,- To edit the last macro or change hotkeys or other settings
  387. Gui,99:Add,Text,y+5 ,like playback speed, choose Settings in the tray menu.
  388. Gui,99:Add,Text,y+10,- Remember to save the settings and restart using Reload.
  389. Gui,99:Add,Picture,xm y+20 Icon5,%applicationname%.exe
  390. Gui,99:Font,Bold
  391. Gui,99:Add,Text,x+10 yp+10,1 Hour Software by Skrommel
  392. Gui,99:Font
  393. Gui,99:Add,Text,y+10,For more tools, information and donations, please visit
  394. Gui,99:Font,CBlue Underline
  395. Gui,99:Add,Text,y+5 G1HOURSOFTWARE,www.1HourSoftware.com
  396. Gui,99:Font
  397. Gui,99:Add,Picture,xm y+20 Icon7,%applicationname%.exe
  398. Gui,99:Font,Bold
  399. Gui,99:Add,Text,x+10 yp+10,DonationCoder
  400. Gui,99:Font
  401. Gui,99:Add,Text,y+10,Please support the contributors at
  402. Gui,99:Font,CBlue Underline
  403. Gui,99:Add,Text,y+5 GDONATIONCODER,www.DonationCoder.com
  404. Gui,99:Font
  405. Gui,99:Add,Picture,xm y+20 Icon6,%applicationname%.exe
  406. Gui,99:Font,Bold
  407. Gui,99:Add,Text,x+10 yp+10,AutoHotkey
  408. Gui,99:Font
  409. Gui,99:Add,Text,y+10,This tool was made using the powerful
  410. Gui,99:Font,CBlue Underline
  411. Gui,99:Add,Text,y+5 GAUTOHOTKEY,www.AutoHotkey.com
  412. Gui,99:Font
  413. Gui,99:Show,,%applicationname% About
  414. hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt") ;IDC_HAND
  415. OnMessage(0x200,"WM_MOUSEMOVE")
  416. Return
  417. 1HOURSOFTWARE:
  418. Run,http://www.1hoursoftware.com,,UseErrorLevel
  419. Return
  420. DONATIONCODER:
  421. Run,http://www.donationcoder.com,,UseErrorLevel
  422. Return
  423. AUTOHOTKEY:
  424. Run,http://www.autohotkey.com,,UseErrorLevel
  425. Return
  426. 99GuiClose:
  427. Gui,99:Destroy
  428. OnMessage(0x200,"")
  429. DllCall("DestroyCursor","Uint",hCur)
  430. Return
  431. WM_MOUSEMOVE(wParam,lParam)
  432. {
  433. Global hCurs
  434. MouseGetPos,,,,ctrl
  435. If ctrl in Static12,Static16,Static20
  436. DllCall("SetCursor","UInt",hCurs)
  437. Return
  438. }
  439. Return
  440. EXIT:
  441. ExitApp