Jump to content

Pause script till key is pushed?


Recommended Posts

  • Developers

I'll look at it again. to be specific I would want it to run the script and just enter a line to tell it to pause until the key is pressed not set a hotkey to pause the script.

Either way works ...

Read the helptopic, have a play with it and in case of issues:show some code you are having problems with.

Jos :)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I looked at the set hotkey help and example. I am trying to understand the principle behind it. First thing that confuses me is Global $paused. I understand that it is setting a variable called $paused but does the variable include all those hotkeys listed below it?

Second thing, I think I understand HotKeySet("{PAUSE}", "TogglePause") as you could set "{PAUSE}" to any key you wanted it to be and "TogglePause" is just the name of the function that you specified which again you could name anything you wanted. Func TogglePause() is just defining the function that you referenced above but then the $Paused= NOT $Paused is a bit confusing. Also confusing to me what command are you actually using that the script regognizes to pause and could you just use that command in a line in the script to pause it at a location until the hotkey to unpause it is used? Like could I just have one of the lines be NOT $Paused and it would pause the script there until I pushed the specified key?

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused

HotKeySet("{PAUSE}", "TogglePause")

HotKeySet("{ESC}", "Terminate")

HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d

;;;; Body of program would go here ;;;;

While 1

Sleep(100)

WEnd

;;;;;;;;

Func TogglePause()

$Paused = NOT $Paused

While $Paused

sleep(100)

ToolTip('Script is "Paused"',0,0)

WEnd

ToolTip("")

EndFunc

Func Terminate()

Exit 0

EndFunc

Func ShowMessage()

MsgBox(4096,"","This is a message.")

EndFunc

Link to comment
Share on other sites

$Paused holds the state of the script: True means script is paused, False means script is not paused.

$Paused = NOT $Paused
just switches from False to True to False.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Ok, I still don't understand it fully but for anyone that wants to do this there is a fairly easy way. I did not know this until now but one of the lines in your script can be TogglePause(). That is the basically activating the function of pausing without pushing the hotkey. It's probably obvious to a lot of people but it wasn't to me.

Another thing, whenever I used the code in the example and I pause the script and then unpause it the script icon for this script in the bottom right hand corner will not go away on it's own even after the script is finished. Anyone else have this issue? I have to right click it and exit or push esc after it's done.

Link to comment
Share on other sites

Does the task manager still show your script before you right click the icon and exit the script?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Can then please post the code you run?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Here is code to a simple script where I get the same problem.

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
MouseClick("left", 27, 38, 1)
TogglePause()
MouseClick("left", 27, 40, 1)
While 1
Sleep(100)
WEnd
;;;;;;;;

Func TogglePause()
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc
Func Terminate()
Exit 0
EndFunc ;==>Terminate
Link to comment
Share on other sites

That is working fine here... i just modified it a bit because of organization.

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

While 1
ToolTip('Script is Running',0,0)
MouseClick("left", 400, 400, 1)
Sleep(500)
WEnd

Func TogglePause()
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc

Func Terminate()
Exit 0
EndFunc ;==>Terminate
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

That is working fine here... i just modified it a bit because of organization.

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

While 1
ToolTip('Script is Running',0,0)
MouseClick("left", 400, 400, 1)
Sleep(500)
WEnd

Func TogglePause()
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc

Func Terminate()
Exit 0
EndFunc ;==>Terminate

One thing I noticed was that you removed the line TogglePause() in between the 2 mouse clicks. The issue I have with this code is that IF you pause it and then resume when it is done it will not go away when the rest of the script has run but if you don't pause it, it will go away just fine. In my experience with this code it doesn't matter if you actually use the pause button during the script or if you make a line in the script TogglePause().

Edited by noobieautolearn
Link to comment
Share on other sites

The OP wants a script that continues after ANY key is pressed.

Here my solution.

;   Wait for key
;
#include <WinAPI.au3>

Beep(500, 300)
_Wait_for_Key()
Beep(800, 300)

Func _Wait_for_Key()
    Global $_Wait_for_Key = 1
    Local $hProc = DllCallbackRegister("_Wait_for_Key_Proc", "long", "int;wparam;lparam")
    Local $hGM = _WinAPI_GetModuleHandle(0)
    Local $handleK = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hProc), $hGM)
    While $_Wait_for_Key
        Sleep(100)
    WEnd
    _WinAPI_UnhookWindowsHookEx($handleK)
    DllCallbackFree($hProc)
    Return
EndFunc   ;==>_Wait_for_Key

Func _Wait_for_Key_Proc($nCode, $wParam, $lParam)
    $_Wait_for_Key = 0
    Return
EndFunc   ;==>_Wait_for_Key_Proc

After the first beep, the script pauses until ANY key is pressed and then beeps again and exits.

BTW: You can extend the script to honor also mouse moves.

Edited by Exit

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

The OP wants a script that continues after ANY key is pressed.

Where have you read that? because i missed it.

@noobieautolearn:

Sorry, didn't understand the problem, it pauses when you press pause, will resume when you press pause again, and will exit when you press escape.

What did you want then?

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Where have you read that? because i missed it.

@noobieautolearn:

Sorry, didn't understand the problem, it pauses when you press pause, will resume when you press pause again, and will exit when you press escape.

What did you want then?

I want it to pause if I push pause, I want it to resume if I push pause. I want it to exit the script if I push esc but I also want it to exit once the script is done running.

The last part does not seem to happen if you pause it during the script and then unpause it. It will do the rest of the actions in the script but will only exit once you push esc even though there is no more lines of code to run.

Did you try the simplified script I posted? If you notice once the pause command was issued and then the script is unpaused even though there is nothing more for it to do it will not exit on it's own.

Edited by noobieautolearn
Link to comment
Share on other sites

That's because it's inside the While loop, you have no exit from it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

;Script
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc
Terminate()

Func Terminate()
Exit 0
EndFunc ;==>Terminate

Is the same as:

;Script
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc

Exit

Do you mean that it works like you want, like this?

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

;Script
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc
Terminate()

Func Terminate()
Exit 0
EndFunc ;==>Terminate

Is the same as:

;Script
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc

Exit

Do you mean that it works like you want, like this?

Hmm It now works the way I want it now, all I did was add Terminate() after the last command and now the script will exit after it has done the last thing.

So for instance, this is the simplified script that works the way I want it. The reason it was not clicking is before I was just used to the script exiting by it's self after the last command but when you add the pause and terminate code it seems you have to tell it to terminate or it stays open.

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
MouseClick("left", 27, 38, 1)
TogglePause()
MouseClick("left", 27, 40, 1)
Terminate()
While 1
Sleep(100)
WEnd
;;;;;;;;

Func TogglePause()
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc
Func Terminate()
Exit 0
EndFunc ;==>Terminate
Edited by noobieautolearn
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...