markronz Posted January 6, 2011 Share Posted January 6, 2011 Hello everyone- I am just trying to write a simple script. All that it does, is when someone presses the 'h' key that it still sends the 'h' keypress and then simulates a left mouse click (at the current position). I would like this scipt to run continuously, monitoring for this h keypress. From searching the forums here, this is what I have written up so far: HotKeySet("h", "Actions") While 1 Sleep(100) WEnd Func Actions() send("h") MouseClick("left") Sleep(5) EndFunc Is this going to form a continuous loop? When I put a message box within the Actions function, it certainly seems like there is an infinite loop type situation going on. Is there some other way I should go about this? Link to comment Share on other sites More sharing options...
markronz Posted January 6, 2011 Author Share Posted January 6, 2011 Wait I think I figured it out! This is my new script: HotKeySet("h", "Actions") While 1 Sleep(100) WEnd Func Actions() HotKeySet("h") Send("h") MouseClick("left") HotKeySet("h", "Actions") Sleep(5) EndFunc A few questions though: 1. Is the While/sleep loop needed at the top? I just want to be sure that this script runs continuously. 2. Any tips on how I would proceed if I only wanted this action to take place if a specific process was running on the machine? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 6, 2011 Moderators Share Posted January 6, 2011 (edited) markronz, Welcome to the AutoIt Forum. Is this going to form a continuous loop?Yes. Is there some other way I should go about this?There are several ways to run infinite loops, but what you have is probably the most common format. However I would add another HotKey to end the script - saves opening Task Manager to do it - along these lines: HotKeySet("{ESC}", "On_Exit") Func On_Exit() Exit EndFunc M23 Edit: Your second atttempt is not good - should have stuck with the first one! As to running for a particular proces, just check in the function if the process exists and return if not: Func Actions() ; If process does not exist then return If Not ProcessExists("fred.exe") Then Return ; So if the process does exist we carry on send("h") MouseClick("left") Sleep(5) ; Not really necessary, but does no harm EndFunc Edited January 6, 2011 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
markronz Posted January 6, 2011 Author Share Posted January 6, 2011 (edited) Hey Melba, thank you for your quick response! I have some follow up questions, but before I do, here is my script as it stands now: Opt("TrayIconHide", 1) ;0=show, 1=hide tray icon HotKeySet("h", "Actions") While 1 Sleep(100) WEnd Func Actions() If ProcessExists("TextPad.exe") Then HotKeySet("h") Send("h") MouseClick("left") HotKeySet("h", "Actions") Sleep(5) EndIf EndFunc As you can see I did use the ProcessExists funtion as you mentioned. Found it right after I posted, sorry about that. I think this accomplishes the same thing as what your code does above. Now you said that my second attempt was not good. I think you may be mistaken, unless I am not understanding something. Coming from the AutoIt Help file, it says directly in there this: ; capture and pass along a keypress HotKeySet("{Esc}", "captureEsc") Func captureEsc() ; ... can do stuff here HotKeySet("{Esc}") Send("{Esc}") HotKeySet("{Esc}", "captureEsc") EndFunc So that was what I was copying. I want to capture the 'h' keypress and perform some actions, however, it seems that if you dont alter the HotKeySet statement as in the above example, that it would just call itself over and over, that continuous loop I was talking about. So you press 'h', it gets caught, the script sends an 'h', which in turn gets caught again and repeats! So I think you need to have those other HotKeySet statements in there so that this does not occur. Hopefully that makes sense. Also, duely noted about the exit (Esc) key. My current script above seems to perform as I desired it to. Do you have any concerns about it being incorrect? Besides the current lack of an escape key? Edited January 6, 2011 by markronz Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 6, 2011 Moderators Share Posted January 6, 2011 markronz,You missed an inportant part of the line I used:If Not ProcessExists("fred.exe") Then ReturnSee the Not in there? It will return only if there is no process - if the process exists it carries on. However, you get your own back with the HotKey setting and unsetting - I did not notice that you were sending the same key as the HotKey itself. Your current code is absolutely correct as you must unset it or you get into recursion problems! We will settle on 15-all for that exchange I think! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
markronz Posted January 6, 2011 Author Share Posted January 6, 2011 Thanks again for the quick response. about the ProcessExists stuff, can you tell me what the difference between your code and mine is? Mine also seems to work: ;YOURS If Not ProcessExists("fred.exe") Then Return ;stuff ;MINE If Not ProcessExists("fred.exe") Then ;stuff EndIf I've tried both yours and mine and both seem to work. Just want to make sure they do the same thing, and one is not better than the other! Thanks! Link to comment Share on other sites More sharing options...
JohnOne Posted January 6, 2011 Share Posted January 6, 2011 Yes, they are the same. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 6, 2011 Moderators Share Posted January 6, 2011 markronz,Your code is Not what you posted before (pun fully intended!) - look carefully at your earlier post. These will produce the same result:If Not ProcessExists("fred.exe") Then Return ;stuff If ProcessExists("fred.exe") Then ;stuff EndIfWhat you just posted will not. It is the Not that makes the difference. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
markronz Posted January 6, 2011 Author Share Posted January 6, 2011 lol oops, sorry, didnt mean to add that Not in there that second time around. Well, anyway, I think I'm all set. Thanks for the help! Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted January 6, 2011 Share Posted January 6, 2011 That Sleep(5) is not doing what you think it's doing. $iTimer = TimerInit() For $iX = 1 To 100 Sleep(5) Next ConsoleWrite(TimerDiff($iTimer) & @CRLF) I've tried both yours and mine and both seem to work. Just want to make sure they do the same thing, and one is not better than the other! Thanks! Melba's look neater to the eye. Looks are less important if you are blind (yes blind people show up on occasion) but even then you would probably take it for the simplicity. It's up to you how to do it. Also you may want to look at _IsPressed, no need for that Send then. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
joe7dust Posted November 1, 2014 Share Posted November 1, 2014 (edited) Sorry for the necro, but after trying about 20 different similar scripts this was the ONLY one that compiled correctly. My problem is that the sleep timer seems to have no effect. As I understood this was supposed to pause for 100 milliseconds in between each loop, but even if I set them as high as 30000 I still get way too many loops per second. I estimate my slightly modified script is running 30 times per second, but I need it to be more like 5 times per second. I just want a left click sent 5 times a second that can be toggled with a hotkey. Here's a rough outline of what I need: KEY::Toggle on/off on=goto loop, else stop loop{left click mouse, sleep 200} Actual script that is running much too fast and ignore the sleep paremeter: expandcollapse popupGlobal $Paused, $Runner HotKeySet("{F10}", "TogglePause") HotKeySet("{ESC}", "Terminate") HotKeySet("{F9}", "ShowMe") ;;;; Body of program would go here ;;;; While 1 Sleep(20000) WEnd ;;;;;;;; Func TogglePause() $Paused = Not $Paused While $Paused Sleep(30000) ToolTip('Script is "Paused"', 0, 0) WEnd ToolTip("") EndFunc ;==>TogglePause Func Terminate() Exit 0 EndFunc ;==>Terminate Func ShowMe() $Runner = Not $Runner While $Runner MouseClick("left") WEnd EndFunc ;==>ShowMe Edited November 1, 2014 by joe7dust Link to comment Share on other sites More sharing options...
joe7dust Posted November 3, 2014 Share Posted November 3, 2014 Sorry for the necro, but after trying about 20 different similar scripts this was the ONLY one that compiled correctly. My problem is that the sleep timer seems to have no effect. As I understood this was supposed to pause for 100 milliseconds in between each loop, but even if I set them as high as 30000 I still get way too many loops per second. I estimate my slightly modified script is running 30 times per second, but I need it to be more like 5 times per second. I just want a left click sent 5 times a second that can be toggled with a hotkey. Here's a rough outline of what I need: KEY::Toggle on/off on=goto loop, else stop loop{left click mouse, sleep 200} Actual script that is running much too fast and ignore the sleep paremeter: expandcollapse popupGlobal $Paused, $Runner HotKeySet("{F10}", "TogglePause") HotKeySet("{ESC}", "Terminate") HotKeySet("{F9}", "ShowMe") ;;;; Body of program would go here ;;;; While 1 Sleep(20000) WEnd ;;;;;;;; Func TogglePause() $Paused = Not $Paused While $Paused Sleep(30000) ToolTip('Script is "Paused"', 0, 0) WEnd ToolTip("") EndFunc ;==>TogglePause Func Terminate() Exit 0 EndFunc ;==>Terminate Func ShowMe() $Runner = Not $Runner While $Runner MouseClick("left") WEnd EndFunc ;==>ShowMe Should I just make a new thread? Link to comment Share on other sites More sharing options...
MikahS Posted November 3, 2014 Share Posted November 3, 2014 (edited) HotKeySet("{F1}", "fiveClicks") HotKeySet("{ESC}", "Quit") While 1 ; run indefinitely WEnd Func fiveClicks() Local $click_Counter = 1 Do MouseClick('left') $click_Counter += 1 Sleep(200) Until $click_Counter = 5 $click_Counter = 1 EndFunc Func Quit() Exit 0 EndFunc something like this? Edited November 3, 2014 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
joe7dust Posted November 3, 2014 Share Posted November 3, 2014 HotKeySet("{F1}", "fiveClicks") HotKeySet("{ESC}", "Quit") While 1 ; run indefinitely WEnd Func fiveClicks() Local $click_Counter = 1 Do MouseClick('left') $click_Counter += 1 Sleep(200) Until $click_Counter = 5 $click_Counter = 1 EndFunc Func Quit() Exit 0 EndFunc something like this? Sort of, when I say "toggle on/off" what I mean is it for to be continuous. Needs to loop endlessly until I cancel it by pressing the hotkey again (or another hotkey if that makes it easier) I could swear that the one here called "the toggle" used to work perfectly, but there may have been a new version of autoit released or something because I had to format my old windows installation and now it gives an error when compiling. http://www.autohotkey.com/board/topic/64576-the-definitive-autofire-thread/ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 3, 2014 Moderators Share Posted November 3, 2014 joe7dust,You do realise that that link is to the AutoHotKey forum and this is the AutoIt forum? Little wonder you had problems compiling. M23 MikahS 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
joe7dust Posted November 3, 2014 Share Posted November 3, 2014 Oh. My. Derp. Sorry for wasting you guys' time. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now