congdantoancau

AutoClick

Jun 27th, 2020
2,169
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. ; #Warn  ; Enable warnings to assist with detecting common errors.
  3. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  4. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  5. #MaxThreadsPerHotkey 2 ; https://autohotkey.com/board/topic/92188-break-a-loop-with-the-same-hotkey-its-pressed/
  6.  
  7. icon := "autoclick.ico"
  8. If FileExist(icon)
  9.     Menu, Tray, Icon, %icon%
  10.  
  11. ; Single click tray icon suspend
  12. ; https://autohotkey.com/boards/viewtopic.php?t=38761
  13. ; https://autohotkey.com/boards/viewtopic.php?t=6110
  14. OnMessage(0x404, "AHK_NOTIFYICON")
  15. AHK_NOTIFYICON(wParam, lParam, uMsg, hWnd)
  16. {
  17.     if (lParam = 0x201) ;WM_LBUTTONDOWN := 0x201
  18.         suspend
  19. }
  20.  
  21. IniRead, delay, Settings.ini, Settings, delay
  22. IniRead, times, Settings.ini, Settings, times
  23.  
  24. Gui, Add, Text,, Delay
  25. Gui, Add, Text,, Times ; 0 means nolimited
  26. Gui, Add, Edit, vDelay w80 y1, %delay%
  27. Gui, Add, Edit, vTimes w80, %times%
  28. Gui, Add, Button, Default w80, Ok
  29.  
  30. Menu, Tray, Add
  31. Menu, Tray, Add, Settings, Settings
  32. Menu, Tray, Add, Stop, Stop
  33. Menu, Tray, Default, Settings
  34.  
  35. Menu, FileMenu, Add, &Open`tCtrl+O, MenuFileOpen
  36. Menu, FileMenu, Add, E&xit, MenuHandler
  37.  
  38. Menu, EditMenu, Add, Copy`tCtrl+C, MenuHandler
  39. Menu, EditMenu, Add, Past`tCtrl+V, MenuHandler
  40. Menu, EditMenu, Add ; with no more options, this is a seperator
  41. Menu, EditMenu, Add, Delete`tDel, MenuHandler
  42.  
  43. Menu, HelpMenu, Add, &About, MenuHandler
  44. Menu, HelpMenu, Add, &Help, MenuFileHelp
  45.  
  46. ; Attach the sub-menus that were created above.
  47. Menu, MyMenuBar, Add, &File, :FileMenu
  48. Menu, MyMenuBar, Add, &Edit, :EditMenu
  49. Menu, MyMenuBar, Add, &Help, :HelpMenu
  50. Gui, Menu, MyMenuBar ; Attach MyMenuBar to the GUI
  51. gui, show, ;w400 h200
  52.  
  53. TrayTip, AutoClick,F5 to start `n● F6 to pause
  54. stopped := 1
  55. return
  56.  
  57. MenuFileOpen:
  58.    MsgBox, Open Menu was clicked
  59. return
  60.  
  61. MenuHandler:
  62.    ;MsgBox You selected %A_ThisMenuItem% from the menu %A_ThisMenu%.
  63.     ;If (A_ThisMenuItem == "&Help")
  64.     ;    MsgBox, ● F5 to start `n● F6 to pause
  65. return
  66.  
  67. MenuFileHelp:
  68.    MsgBox,F5 to start `n● F6 to pause
  69. return
  70.  
  71. Stop:
  72.    stopped := 1
  73.     TrayTip, AutoClick, AutoClick is stopped.
  74. return
  75.  
  76. ButtonOk:
  77.    Gui, Submit
  78.     IniWrite, %delay%, Settings.ini, Settings, delay
  79.     IniWrite, %times%, Settings.ini, Settings, times
  80. return
  81.  
  82. Settings:
  83.    Gui, Show
  84. return
  85.  
  86. GuiEscape:
  87.     Gui, Cancel
  88. return
  89.  
  90. F5::
  91.     If stopped {
  92.         TrayTip, AutoClick, AutoClick is working. . .
  93.         SetTimer, Trigger, -1
  94.     } else {
  95.         TrayTip, AutoClick, AutoClick is stopped.
  96.     }
  97.     stopped:=!stopped
  98. return
  99.  
  100. Trigger:
  101.    While (!stopped and times) ; both condition is NOT match will stop the loop
  102.     {
  103.         if (times > 0)
  104.             times--
  105.         Send {LButton}
  106.         Sleep, Delay
  107.     }
  108. /*
  109.     Loop
  110.     {
  111.         if (times > 0)
  112.             times--
  113.         if (stopped == 1 or times == 0) ; one condition is match will stop the loop
  114.             break
  115.         Send {LButton}
  116.         Sleep, Delay
  117.     }
  118. */
  119. Return
  120. /*
  121. F5::
  122.     ; stopped := !stopped ; this toggle will work fine instead of if condition with no TrayTip
  123.    
  124.     if (!stopped) {
  125.         stopped := 1
  126.         TrayTip, AutoClick, AutoClick is stopped.
  127.     } else {
  128.         stopped := 0
  129.         TrayTip, AutoClick, AutoClick is working. . .
  130.     }
  131.     If (times == 0) { ; infinity loop
  132.         Loop
  133.         {
  134.             if (stopped == 1)
  135.                 break
  136.             Send {LButton}
  137.             Sleep, Delay
  138.         }
  139.     } else { ; limited loop
  140.         Loop, times
  141.         {
  142.             if (stopped == 1)
  143.                 break
  144.             Send {LButton}
  145.             Sleep, Delay
  146.         }
  147.     }
  148. return
  149. */
  150. F6:: Pause
RAW Paste Data