Sign in to follow this  
Followers 0
newcomer44

Halt script automatically and resume via hotkey

6 posts in this topic

Hello,

as the title says, I want to break a script without pressing a key and resume it per hotkey.

Many thanks in advance.

Share this post


Link to post
Share on other sites



Example:

#include <date.au3>
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")

#include <GUIConstants.au3>

$Form1 = GUICreate("Form1", 294, 85, 193, 125)
$Label1 = GUICtrlCreateLabel("Label1", 24, 24, 236, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    $time = _NowCalc()
    GUICtrlSetData($Label1, $time)
    Sleep(50)
WEnd


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

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

HotKeySet("{f5}", "_process")
Global $giStep = 0
main()
Func main()
While 1
  Sleep(10)
WEnd
EndFunc   ;==>main
Func _process()
Switch $giStep
  Case 0
   $giStep += _step($giStep)
   Return (1)
  Case 1
   $giStep += _step($giStep)
   Return (1)
  Case 2
   $giStep += _step($giStep)
   Return (1)
  Case 3
   Exit
EndSwitch
EndFunc   ;==>_process
Func _Step($giStep)
ConsoleWrite(@LF & "This should do stuff! " & $giStep & @LF)
Return (1)
EndFunc   ;==>_Step

Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hello,

thanks for your proposals.

This is nearly what I mean:

Run("notepad.exe")
WinWaitActive("[CLASS:Notepad]")
Send("This is a testline before the enter key was pressed." & @LF)
Send("This is a testline before the enter key was pressed." & @LF)
; --------------------------------------------------------------------
#include<Misc.au3>
$dll = DllOpen("user32.dll")
While 1
Sleep(250)
If _IsPressed("0D", $dll) Then ; enter
  ExitLoop
Else
  MsgBox(0, "confirmation", "Press <ENTER> to confirm")
EndIf
WEnd
DllClose($dll)
; --------------------------------------------------------------------
Sleep(500)
Send(@LF)
Send(@LF)
Send("This is a testline after the enter key was pressed." & @LF)
Send("This is a testline after the enter key was pressed." & @LF)
Exit

The problem is, that I have to press the enter key too long, in order to continue the script flawlessly.

Edited by newcomer44

Share this post


Link to post
Share on other sites

But you coded it to take a long time. Imagine that Enter is pressed straight after the _IsPressed(), you have a 250 ms Sleep() so it would have to be pressed for 250 ms!

Unless you need the Enter for something else, use HotKeySet() instead of _IsPressed(). Or since it's just notepad you're automating, one of the Control*() functions, or write directly to the file with something like FileWrite().

Share this post


Link to post
Share on other sites

Now I understand.

All I had to do,

was to reduce the Sleep(250) value to Sleep(10).

Thanks at all.

Share this post


Link to post
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
Sign in to follow this  
Followers 0