furian Posted December 2, 2020 Share Posted December 2, 2020 (edited) Need some help figuring out this out! The first example works, but it only looks if F6 is held down, and cycles through my functions as long as the key is held down. I want it to use a separate list of functions depending on if F5 or F6 key is held down, which i attempted in the 2nd example, but it doesn't work properly. It seems to fire off one function, but then just dies off. Lastly I'd like to try to make this function the same way without holding the key down, but rather pressing a key repeatedly. Is this possible? expandcollapse popupOpt("SendKeyDelay", 50) ;5 milliseconds #include <Misc.au3> #include <Date.au3> #include <Math.au3> #include <MsgBoxConstants.au3> Func Do1() If PixelGetColor(1005, 1352) = 0xFF0BDB Then Send ("a") EndIf EndFunc Func Do2() If PixelGetColor(994, 1321) <> 0xFB1626 Then Send ("b") Sleep ( 1000 ) EndIf EndFunc Func Do3() If PixelGetColor(994, 1370) <> 0xEFFB0D Then Send ("c") Sleep ( 1000 ) EndIf EndFunc While 1 if not _IsPressed(75) then ContinueLoop Do1() Sleep ( 50 ) if not _IsPressed(75) then ContinueLoop Do2() Sleep ( 50 ) if not _IsPressed(75) then ContinueLoop Do3() Sleep ( 50 ) Wend expandcollapse popupOpt("SendKeyDelay", 50) ;5 milliseconds #include <Misc.au3> #include <Date.au3> #include <Math.au3> #include <MsgBoxConstants.au3> Func Do1() If PixelGetColor(1005, 1352) = 0xFF0BDB Then Send ("a") EndIf EndFunc Func Do2() If PixelGetColor(994, 1321) <> 0xFB1626 Then Send ("b") Sleep ( 1000 ) EndIf EndFunc Func Do3() If PixelGetColor(994, 1370) <> 0xEFFB0D Then Send ("c") Sleep ( 1000 ) EndIf EndFunc Func Do1Loop() While 1 if not _IsPressed(75) then ContinueLoop Do1() Sleep ( 50 ) if not _IsPressed(75) then ContinueLoop Do3() Sleep ( 50 ) if _IsPressed(75) then DetermineLoop() Wend EndFunc Func Do2Loop() While 1 if not _IsPressed(76) then ContinueLoop Do2() Sleep ( 50 ) if not _IsPressed(76) then ContinueLoop Do3() Sleep ( 50 ) if _IsPressed(76) then DetermineLoop() Wend EndFunc Func DetermineLoop() While 1 if not _IsPressed(75) then TheSingleLoop() if not _IsPressed(76) then TheMultiLoop() WEnd EndFunc DetermineLoop() Edited December 2, 2020 by furian Link to comment Share on other sites More sharing options...
Nine Posted December 2, 2020 Share Posted December 2, 2020 Maybe using HotKeySet instead of _IsPressed ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Dan_555 Posted December 2, 2020 Share Posted December 2, 2020 You would probably want to do something like this: Global $vTrack=0 HotKeySet ("{F5}","DoIt") Func DoIt() $vTrack = $vTrack + 1 if $vTrack>4 then $vTrack=1 Switch $vTrack Case 1 ConsoleWrite ("1"&@crlf) Case 2 ConsoleWrite ("2"&@crlf) Case 3 ConsoleWrite ("3"&@crlf) Case 4 ConsoleWrite ("4"&@crlf) EndSwitch EndFunc While 1 sleep(50) WEnd Some of my script sourcecode Link to comment Share on other sites More sharing options...
furian Posted December 2, 2020 Author Share Posted December 2, 2020 Thats close Dan_555, but it fires everything at once. I need it to step through each "case" as you have it here, as long as the F5 key is repeating, then once the F5 key stops repeating, stop, and reset. This may not be possible the more I think about it. Link to comment Share on other sites More sharing options...
Dan_555 Posted December 2, 2020 Share Posted December 2, 2020 Can you explain more of what you want to achieve ? Here is a script which cycles though each step of the function, by pressing and releasing the f5 key: #include <Misc.au3> Global $vTrack = 0, $vLock = 0 Global $hDLL = DllOpen("user32.dll") HotKeySet("{F5}", "DoIt") Func DoIt() If $vLock = 0 Then $vLock = 1 $vTrack = $vTrack + 1 If $vTrack > 4 Then $vTrack = 1 Switch $vTrack Case 1 ConsoleWrite("1" & @CRLF) Case 2 ConsoleWrite("2" & @CRLF) Case 3 ConsoleWrite("3" & @CRLF) Case 4 ConsoleWrite("4" & @CRLF) EndSwitch While _IsPressed("74", $hDLL) = True ;F5 WEnd $vLock=0 EndIf EndFunc ;==>DoIt While _IsPressed("1b", $hDLL) = False ;Escape WEnd DllClose($hDLL) Some of my script sourcecode Link to comment Share on other sites More sharing options...
furian Posted December 2, 2020 Author Share Posted December 2, 2020 I think that just about does it Dan, thank you very much! I just need to understand what you did here now! Link to comment Share on other sites More sharing options...
Dan_555 Posted December 3, 2020 Share Posted December 3, 2020 (edited) Well, while my first script has checked for the release of the F5, the "hotkey" is calling the function again and again, whenever autoit/windows detects the keypress and so the repeats happened. All i did is to lock the call of the function (at the first function call), and to unlock the function for the next use (when the f5 key was released). And, i think, for the repeated usage of the _isPressed function, you should open and (at the end) close the user32.dll with: Local $hDLL = DllOpen("user32.dll") Edited December 3, 2020 by Dan_555 Some of my script sourcecode 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