1
votes

How can I write a .ahk script to automate the process of "press and hold 'key1' 2 second", "press and hold 'key2' 2 seconds", "press and hold 'key3' 2 seconds", "right click, wait 2 seconds", and repeat.

I've never scripted for automated actions on the keyboard before so this is all new territory for me. I assume anyone with some experience could implement the above in a minute or two.

EDIT: I would also like to be able to call this script to start with some sort of key combination, like "wait for alt+a , then execute".

1

1 Answers

2
votes

Hope this get's you going..

!a:: ; Alt+a to start script
Loop 
{ ; Start of loop
    GetKeyState, keystate, Pause, P ; Get the state of the Pause key
    if keystate = D  ; The Pause key was held down, break out of the loop.
        break ; Stop loop when the Pause key was held down
    Send, {Space Down} ; This will NOT autorepeat
    Sleep 2000 ; Wait 200 ms
    Send, {Space Up} ; Release the key
    GetKeyState, keystate, Pause, P ; Get the state of the Pause key
    if keystate = D  ; The Pause key was held down, break out of the loop.
        break ; Stop loop when the Pause key was held down
    Send, {b Down} ; This will NOT autorepeat
    Sleep 2000 ; Wait 200 ms
    Send, {b Up} ; Release the key
    GetKeyState, keystate, Pause, P ; Get the state of the Pause key
    if keystate = D  ; The Pause key was held down, break out of the loop.
        break ; Stop loop when the Pause key was held down
    MouseClick, left, 150,150 ; Click the mouse at 150X,150Y pixels, check exact mouse coordinates with AHK Window Spy
} ; End of loop
return ; End of script

P.s. Instead of adding the Break trap after each key, you could also add a hotkey to run exitapp.