ponchato Posted August 22, 2009 Posted August 22, 2009 I'm writing a script to click and type in different areas of the screen. That's easy to figure out, no problem. What I'm having trouble with is figuring out how to pause or restart a script when I press a hotkey. Global $Paused HotKeySet("{PAUSE}", "Pause") While 1 *The 'action' part of the script goes here* WEnd Func Pause() $Paused = Not $Paused While $Paused Sleep(1000) ToolTip("Script is paused.") WEnd EndFunc I'm sure that will work for pausing the script, because I've used the exact same lines in a few other scripts. What I don't know how to do is make the script restart from the beginning when I press another hotkey. Any ideas?
CodyBarrett Posted August 22, 2009 Posted August 22, 2009 (edited) Global $Paused = 0 HotKeySet("{PAUSE}", "Pause") While 1 sleep (100) ; to keep CPU usage down WEnd Func Pause() If $Paused = 0 then $Paused = 1 ElseIf $Paused = 1 then $Paused = 0 Endif While $Paused = 1 Sleep(1000) ToolTip("Script is paused.") WEnd EndFunc EDIT as for the starting over again... there are a few ways... if its a small size script.. make what you want to restart in a funciton and just recall that function Edited August 22, 2009 by CodyBarrett [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size]
Yashied Posted August 22, 2009 Posted August 22, 2009 Global $Paused = 0 HotKeySet("{PAUSE}", "Pause") While 1 sleep (100) ; to keep CPU usage down WEnd Func Pause() If $Paused = 0 then $Paused = 1 ElseIf $Paused = 1 then $Paused = 0 Endif While $Paused = 1 Sleep(1000) ToolTip("Script is paused.") WEnd EndFunc EDIT as for the starting over again... there are a few ways... if its a small size script.. make what you want to restart in a funciton and just recall that function You can write a more simple. $Paused = Not $Paused My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
CodyBarrett Posted August 22, 2009 Posted August 22, 2009 true nuff [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size]
Firstone Posted August 23, 2009 Posted August 23, 2009 I'm abit confused, did u want to use the same hotkey for the pause button and to resume the script? or use a different hotkey to start the script from the start? Also when u meant restart the script did u mean the first while loop?
geasiki Posted August 23, 2009 Posted August 23, 2009 Try this. Global $Paused = "OFF" HotKeySet("{PAUSE}", "Pause") While 1 If $Paused = "ON" Then _DoThis() sleep(100) WEnd Func Pause() If $Paused = "OFF" Then $Paused = "ON" Else $Paused = "OFF" EndIf
ponchato Posted August 23, 2009 Author Posted August 23, 2009 I'm abit confused, did u want to use the same hotkey for the pause button and to resume the script? or use a different hotkey to start the script from the start?Also when u meant restart the script did u mean the first while loop?One hotkey for pausing, and one for restarting, and yes restarting the first while loop. Thanks for asking, I wasn't sure if it was clear.
Firstone Posted August 23, 2009 Posted August 23, 2009 One hotkey for pausing, and one for restarting, and yes restarting the first while loop. Thanks for asking, I wasn't sure if it was clear. Ahh cool, well you just need to make ur action a function and set a hotkey to it then. Global $Paused HotKeySet("{PAUSE}", "Pause") HotKeySet("{HOME}", "Action") Func Action() While 1 *The 'action' part of the script goes here* WEnd EndFunc Action() ; so action starts when script is opened Func Pause() $Paused = Not $Paused While $Paused Sleep(1000) ToolTip("Script is paused.") WEnd EndFunc
Firstone Posted August 23, 2009 Posted August 23, 2009 One hotkey for pausing, and one for restarting, and yes restarting the first while loop. Thanks for asking, I wasn't sure if it was clear. Ahh cool, well you just need to make ur action a function and set a hotkey to it then. Global $Paused HotKeySet("{PAUSE}", "Pause") HotKeySet("{HOME}", "Action") Func Action() While 1 *The 'action' part of the script goes here* WEnd EndFunc Action() ; so action starts when script is opened Func Pause() $Paused = Not $Paused While $Paused Sleep(1000) ToolTip("Script is paused.") WEnd EndFunc
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