Jump to content

Can Autoit hold down two keys when I hold down one?


Recommended Posts

I am trying to make an auto-sprint macro.

I want to make it so when I press W in my game autoit hits , and . at the same time.

The tricky part is that I want it so when I hold down W it holds down , and . and when I let go of w it lets go of , and .

I DON'T want it so when I press W (down up) it toggles , and . being held down.

This can be done easily in Autohotkey but I can't figure it out in Autoit and I much prefer to use Autoit.

I tried the following with no luck

HotKeySet("{w down}", "SprintOn")
HotKeySet("{w up}", "SprintOff")

While 1
Sleep (100)
WEnd

Func SprintOn()
    Send("{, down}")
    Send("{. down}")
EndFunc

Func SprintOff()
    Send("{, up}")
    Send("{. up}")
EndFunc
Edited by Aro2220
Link to comment
Share on other sites

Hi and Welcome to the forum!

Unfortunately HotKeySet() can't do what you want, as you have seen. The typical way of solving this in AutoIt is _IsPressed(). Here's the example from the helpfile modified based on your info above:

#Include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1
    Sleep (10)
    If _IsPressed("57", $dll) Then
        Send("{, down}")
        Send("{. down}")
        While _IsPressed("57", $dll)
            Sleep(10)
        WEnd
        Send("{, up}")
        Send("{. up}")
    EndIf
WEnd
Link to comment
Share on other sites

This might work:

HotKeySet ("w", "Sprint")
Global $SprintConstOFF = 0
Global $SprintConstON = 1
Global $SprintConstCOASTING = 2


Global $gSprintingState = $SprintConstOFF

Func Sprint ()
    Send("{, down}")
    Send("{. down}")
    $gSprintingState = $SprintConstON
EndFunc

While 1
    If $gSprintingState = $SprintConstON then
        $gSprintingState = $SprintConstCOASTING ; This allows test to reset
        Sleep (10)
    ElseIf $gSprintingState = $SprintConstCOASTING Then 
        Send("{, up}")
        Send("{. up}")
        $gSprintingState = $SprintConstOFF
        Sleep (10)
    Else
        Sleep (100)
    EndIf
WEnd

Gotchas: This will block the 'w' from being sent to your game, you'd need to do this to send it through, and there will probably be a performance hit for doing it:

HotKeySet("w")
Send ("w", 1)
HotKeySet("w", "Sprint")

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

Hi and Welcome to the forum!

Unfortunately HotKeySet() can't do what you want, as you have seen. The typical way of solving this in AutoIt is _IsPressed(). Here's the example from the helpfile modified based on your info above:

#Include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1
    Sleep (10)
    If _IsPressed("57", $dll) Then
        Send("{, down}")
        Send("{. down}")
        While _IsPressed("57", $dll)
            Sleep(10)
        WEnd
        Send("{, up}")
        Send("{. up}")
    EndIf
WEnd

Hey Admiral, I tried out your script and it works perfectly!!

Thanks for teaching me the new commands I was looking for.

I don't understand the include line though since I don't have a misc.au3 file (I searched my computer)

What does that line do?

Link to comment
Share on other sites

I don't understand the include line though since I don't have a misc.au3 file (I searched my computer)

What does that line do?

I don't think I could explain it any better than the helpfile do. Just write #include in the index, use the search, or browse to it manually, it's under "Keyword/Statement Reference".

It will explain both where the file could be (multiple choices, yay!) and what it does.

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...