How to autofire F in Autohotkey?

The Dowsing Rod requires you to spam the use (F) key while looking for deep arrowheads. Spamming keys sucks. You wouldn’t really need it if sound was enough clue to go on (the PS2 version made your controller rumble when in position), but it turns out it’s not.

AutoHotKey should be able to make it much easier on my fingers. Something such as this should suffice:

  • How do I remap the arrow keys using AutoHotkey?
  • $f::
    While GetKeyState("f","P")
     Send f
    return
    

    It works in all places but Psychonauts. I’ve tried the SendPlay, the SendInput, the SendMode Play, the SetKeyDelay workarounds suggested here to no avail.

    How can I make searching with the dowsing rods less tedious?

  • How do I remap the arrow keys using AutoHotkey?
  • 4 Solutions collect form web for “How to autofire F in Autohotkey?”

    I tried a different approach with the “automatic shooting” function that JoyToKey offers, but the problem seems to be in Psychonauts itself. While it does register keys remapped through JoyToKey, it does not accept repeated inputs without registering a release of the button you pressed.

    This led me to the idea to send raw input events, which works. In this AHK example I just assigned the hotkey CTRL-r to make Raz jump 20 times.

    ^r::
    Loop 20
    {
        Send {Space down}
        Sleep 10
        Send {Space up}
        Sleep 1000
    }
    return
    

    Should work with any other key as well.

    I finally got it to work

    loop
    {
    ^#f::
    If getkeystate("f")
        send {f up}
    else
        loop
            {
            send {f down}
            sleep 20
            send {f up}
            sleep 20
            if getkeystate("f")
                break
            }
    return
    }
    

    I have the Mac version of Psychonauts, so I used Sikuli as the scripting engine, which works on both Windows and Mac. Sikuli uses Python as its scripting language.

    This script presses F every 0.12 seconds until either 30 seconds has passed or you stop the script with C. You can configure it by changing the values of the constants at the top.

    # Psychonauts: repeat F to collect deep arrowheads
    
    APP_NAME = "Psychonauts"
    KEY_TO_MASH = "f"
    TIME_TO_RUN = 30*1 + 00
    TIME_OF_PRESS = 0.02
    TIME_OF_WAIT = 0.10
    
    def holdKeyForTime(key, time):
        keyDown(key)
        wait(time)
        keyUp(key)
    
    def mainAction():
        time_to_run = TIME_TO_RUN
        time_of_press = TIME_OF_PRESS
        time_of_wait = TIME_OF_WAIT
        time_per_press = time_of_press + time_of_wait
        num_presses = time_to_run / time_per_press
    
        for i in range(num_presses):
            holdKeyForTime(KEY_TO_MASH, time_of_press)
            wait(time_of_wait)
    
    App.focus(APP_NAME); wait(1)
    mainAction()
    
    
    # full docs: http://doc.sikuli.org/
    
    ^1::
         SetTimer, AUTOFIRE, 10
         Gosub, AUTOFIRE
    return
    ^2::
         SetTimer, AUTOFIRE, Off
    return
    
    AUTOFIRE:
         Send, F
    return
    
    We love Playing Games, especially Video Games.