herecamealbert Posted December 14, 2011 Share Posted December 14, 2011 Hi all, I just wrote a script that seems to loop until I press my specified key, as summarised below: HotKeySet("`", "QuitLoop"); $counter = 0 Func QuitLoop() $counter=1 EndFunc While $counter=0 [b]BODY[/b] WEnd What this clearly does is, upon execution of the exe, loops the body of the while function, which was my idea. However, after pressing "`" to increment the counter variable and stop the while loop, the program ends. My intention is to reuse the "`" key to start the while loop at my discretion, after another keypress, to the following effect: Run exe, while loop running hit `, while loop stops x seconds/minutes later, hit `, while loop restarts rinse and repeat to my joy Thanks in advance! Link to comment Share on other sites More sharing options...
Damein Posted December 14, 2011 Share Posted December 14, 2011 This is how I like to do my setup HotKeySet("`", "CheckLoop") Global $Counter _LoopOn() Func CheckLoop() If $Counter = 0 Then $Counter = 1 _LoopOff() Else $Counter = 0 MsgBox(0, "Test", $Counter) _LoopOn() EndIf EndFunc Func _LoopOn() While $Counter = 0 Sleep(1000) MsgBox(0, "Test", "Loop on") WEnd EndFunc Func _LoopOff() MsgBox(0, "Test", "Loop off") EndFunc While 1 Sleep(10) WEnd Let me know if anything is confusing! Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic Link to comment Share on other sites More sharing options...
herecamealbert Posted December 14, 2011 Author Share Posted December 14, 2011 This is how I like to do my setup HotKeySet("`", "CheckLoop") Global $Counter _LoopOn() Func CheckLoop() If $Counter = 0 Then $Counter = 1 _LoopOff() Else $Counter = 0 MsgBox(0, "Test", $Counter) _LoopOn() EndIf EndFunc Func _LoopOn() While $Counter = 0 Sleep(1000) MsgBox(0, "Test", "Loop on") WEnd EndFunc Func _LoopOff() MsgBox(0, "Test", "Loop off") EndFunc While 1 Sleep(10) WEnd Let me know if anything is confusing! Hi! Your code works fine but when I press "`" to turn the loop off the script terminates rather than... enters sleep, for lack of better terms lol. I essentially want to be able to press "`" a potentially infinite amount of times before I decide to terminate the script. In case it's my error I bunged the while body required in the LoopOn() function after sleep(1000), replacing the message box. Please help and thanks again! Link to comment Share on other sites More sharing options...
herecamealbert Posted December 14, 2011 Author Share Posted December 14, 2011 One other thing: Shift will not register at all, the relevant code in the while loop is: Send("{+ down}") Sleep(5000) Send("{+ up}") Sleep(5000) For a clear example to hold the shift key down when I'm in VLC or powerDVD or powerDirector render mode etc... I've replaced that bit of the while loop with another key such as "5" to test that a key is being held down correctly, and it is - just not shift! Are there any other alternatives to coding the holding of shift? I've tried the options KeyDelay and KeyDownDelay with no joy, more issues! Link to comment Share on other sites More sharing options...
somdcomputerguy Posted December 14, 2011 Share Posted December 14, 2011 The syntax is incorrect. It should be like this - Send("+{DOWN}")I don't know if case matters, try it either way if you wish. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. 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