Jump to content
furian

Stepping through function with each key press?

Recommended Posts

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?

 

Opt("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
Opt("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 by furian

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

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.

 

 

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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 by Dan_555

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...