Jump to content

hotkeys?


Recommended Posts

hello

id like to set a hotkey (ESC) and when i press it i restart the current loop.

can someone help me put it into this code?

#include <Misc.au3>

While 1
$1 = InputBox("test", "write something")
$2 = MsgBox(4, "continue?", "would u like to continue?")
If $2 = 7 Then
    Exit
ElseIf $2 = 6 Then
$3 = InputBox("test", "write something")
EndIf
$4 = MsgBox(4, "continue?", "would u like to continue?")
If $4 = 7 Then
    Exit
EndIf
MsgBox(0, "waiting for keystroke S", "waiting for keystroke S")
While 1
If _IsPressed("53") Then
    ExitLoop
EndIf
WEnd
MsgBox(0, "done1", "done!")
ExitLoop
WEnd

While 1
$5 = InputBox("test", "write something")
$6 = MsgBox(4, "continue?", "would u like to continue?")
If $6 = 7 Then
    Exit
ElseIf $6 = 6 Then
$7 = InputBox("test", "write something")
EndIf
$8 = MsgBox(4, "continue?", "would u like to continue?")
If $8 = 7 Then
    Exit
EndIf
MsgBox(0, "waiting for keystroke S", "waiting for keystroke S")
While 1
If _IsPressed("53") Then
    ExitLoop
EndIf
WEnd
MsgBox(0, "done2", "done!")
WEnd

//Bill

Edited by bills
Link to comment
Share on other sites

Hm, I think I dont get exactly what your problem is, but how about ContinueLoop? Read the help, you can give a level for which loop to continue.

Id like a hotkey so that when in in the 2nd while loop ( the one inside the first one) and i click "ESC" i restart the first while loop. I should be able to press the hotkey at any point during the script to restart the first while loop.

Ive looked at Continueloop in the helpfiles but frankly i dont understand how to use it.

Link to comment
Share on other sites

Why doing this so complicated? Why dont you put the loop code into a function which is called with a keypress and a while loop which does nothing but wait? Just like the example given in the help for the HotKeySet function. I think this is all you need.

Link to comment
Share on other sites

Id like a hotkey so that when in in the 2nd while loop ( the one inside the first one) and i click "ESC" i restart the first while loop. I should be able to press the hotkey at any point during the script to restart the first while loop.

Ive looked at Continueloop in the helpfiles but frankly i dont understand how to use it.

Set up a global flag, like:

Global $RestartLoop = False

Your hot key function just toggles that flag to True.

Your inner While loop monitors the Global flag, and if it ever gets set, ExitLoop's to the outer While loop.

Your outer While loop monitors the Global flag too, and if it sees it set:

1. Sets it back to False

2. Restarts whatever it was doing.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Set up a global flag, like:

Global $RestartLoop = False

Your hot key function just toggles that flag to True.

Your inner While loop monitors the Global flag, and if it ever gets set, ExitLoop's to the outer While loop.

Your outer While loop monitors the Global flag too, and if it sees it set:

1. Sets it back to False

2. Restarts whatever it was doing.

:)

Nice! Cant find it in the helpfile though, can you give me an example with the code above?

Thanks

Link to comment
Share on other sites

Nice! Cant find it in the helpfile though, can you give me an example with the code above?

Thanks

Demo of the logic:

HotKeySet("{HOME}", "_Restart") ; Hit "HOME" to start over
HotKeySet("{END}", "_Quit") ; Hit "END" to exit

Global $Restart = False, $x = 0, $y = 0

While 1
    $y = 0
    While 1
        ToolTip("x = " & $x & "   y = " & $y)
        $y += 1
        If $y = 10 Or $Restart Then ExitLoop
        Sleep(200)
    WEnd
    If $Restart Then
        $Restart = False
        $x = 0
    Else
        $x += 1
    EndIf
WEnd

Func _Restart()
    $Restart = True
EndFunc   ;==>_Restart

Func _Quit()
    Exit
EndFunc   ;==>_Quit

:rolleyes:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Demo of the logic:

HotKeySet("{HOME}", "_Restart") ; Hit "HOME" to start over
HotKeySet("{END}", "_Quit") ; Hit "END" to exit

Global $Restart = False, $x = 0, $y = 0

While 1
    $y = 0
    While 1
        ToolTip("x = " & $x & "   y = " & $y)
        $y += 1
        If $y = 10 Or $Restart Then ExitLoop
        Sleep(200)
    WEnd
    If $Restart Then
        $Restart = False
        $x = 0
    Else
        $x += 1
    EndIf
WEnd

Func _Restart()
    $Restart = True
EndFunc   ;==>_Restart

Func _Quit()
    Exit
EndFunc   ;==>_Quit

:rolleyes:

Okay i got about 6000 lines of code which i was planning on putting the hotkey in.

Whats with the $x's and $y's?

Link to comment
Share on other sites

Okay i got about 6000 lines of code which i was planning on putting the hotkey in.

Whats with the $x's and $y's?

I'm pretty sure he was just having the script doing something while waiting for the hotkey presses

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

I'm pretty sure he was just having the script doing something while waiting for the hotkey presses

Okay then i cant get it to work :rolleyes:

Can anyone help me to get it to work in the code above?

Link to comment
Share on other sites

Okay then i cant get it to work :rolleyes:

Can anyone help me to get it to work in the code above?

I think I see where your issue comes from...

You may not be aware that the Inputbox function actually pauses the script while waiting for input.

Look at this example for instance:

$count = 0
While 1
    $count += 1
    $answer = InputBox("Question", "Make the answer longer" & _
            " than 3 chars to exit", "xyz", "", -1, -1, 0, 0)
    MsgBox(4096, "Info", "$answer : " & $answer & @CRLF & _
            "$count : " & $count)
    If StringLen($answer) > 3 Then ExitLoop
WEnd

If you run that, you will see that if you hit the ESC key it just closes the input box and provides nothing to the variable you are assigning it to. Your script is not continuing to loop while waiting for input.

Perhaps you should look at creating your own GUI for the boxes and include logic for the various Hotkeys you are wanting to use.

Check out the samples in the helpfile for GUICtrlCreateInput and HotKeySet

Or alternatively, you could modify your original code to check for a lack of input from the latter input boxes and if they = "" then go back to your first question.

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

If i make an write like this:

If Not _IsPressed("1B") Then
blabla
blablabla
While 1
If _IsPressed("43") Then
ExitLoop
EndIf
WEnd
blablabla
EndIf

Is the first If valid through the entire If - EndIf?

I mean does it end the IF-EndIF if i press escape in the While loop in the middle?

Link to comment
Share on other sites

Is the first If valid through the entire If - EndIf?

I mean does it end the IF-EndIF if i press escape in the While loop in the middle?

No.

The condition is tested when the If is executed. There is no further checking for a change in the condition unless you code it in there. In a While\WEnd loop, the condition is only checked at the times the While statement is evaluated. In a Do\Until loop the check only occurs when the Until statement is evaluated.

:rolleyes:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...