Trying to create a macro, but im bad at coding

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
r00173
Posts: 5
Joined: 01 Jun 2023, 05:50

Trying to create a macro, but im bad at coding

Post by r00173 » 01 Jun 2023, 05:56

I'm not a programmer, I just want my pc to hold my d and space bar for ~19s and then hold my s and space bar for ~ 19s, loop it a few times and have a button to pause the script. Pls help i have no idea what im doing.
image.png
image.png (10.15 KiB) Viewed 302 times

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Trying to create a macro, but im bad at coding

Post by mikeyww » 01 Jun 2023, 06:24

Welcome to this AutoHotkey forum!

Why release the key immediately if you actually want to keep it pressed? You can send the key up after the sleep.

Did you write this script?

Why are you posting an image of your script, instead of actual code?

What happens when you run this script?

r00173
Posts: 5
Joined: 01 Jun 2023, 05:50

Re: Trying to create a macro, but im bad at coding

Post by r00173 » 01 Jun 2023, 06:41

1) thats true, how would I format it to have all the keypresses as down, then sleep then up? Like this

Code: Select all

1: SendInput "{d down}" "{Spacedown]"
sleep 19000
SendInput "{d up}" "{a down}"
sleep 19000
SendInput "{a up}" "{space up}"
[Mod edit: [code][/code] tags added. Please use them yourself going forward.]

2) I did write it but I'm just reading the start guide and using commands that I think should work I have no idea how to code a macro
3) Idk, If sending the actual code is easier I'll send that in the future
4) running the script says line 8 is missing it's opening brace

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Trying to create a macro, but im bad at coding

Post by mikeyww » 01 Jun 2023, 07:01

You are on the right track. Below is a revision that you can adjust. You were mixing v1 and v2 code-- not allowed! If you want v2, then use the v2 documentation.

Code: Select all

#Requires AutoHotkey v2.0
wait := 500

1:: {
 Send '{d down}{Space down}'
 Sleep wait
 Send '{d up}{a down}'
 Sleep wait
 Send '{a up}{Space up}'
 SoundBeep 1500
}
You can add a hotkey that calls the Pause function, keeping in mind that one or more keys may be down at that time.

r00173
Posts: 5
Joined: 01 Jun 2023, 05:50

Re: Trying to create a macro, but im bad at coding

Post by r00173 » 01 Jun 2023, 07:23

ty I'll try this

r00173
Posts: 5
Joined: 01 Jun 2023, 05:50

Re: Trying to create a macro, but im bad at coding

Post by r00173 » 01 Jun 2023, 08:01

Code: Select all

#Requires AutoHotkey v2.0

wait := 19500
loopCount := 0
isPaused := false

^t:: ; Toggle switch hotkey
{
    if (isPaused) {
        isPaused := false
        MsgBox, Script is now resumed.
    } else {
        isPaused := true
        MsgBox, Script is now paused.
    }
    return
}

`::
{
    if (isPaused)
        return
    
    loopCount := 0
    While (loopCount < 10)
    {
        Send, {d down}{Space down}
        Sleep, wait
        Send, {d up}{s down}
        Sleep, wait
        Send, {s up}{Space up}
        SoundBeep, 1500
        loopCount++
    }
    return
}

[Mod edit: fixed [code][/code] tags.]

there's something wrong when I try to pause it like this, but I'm not sure how to use suspend

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Trying to create a macro, but im bad at coding

Post by mikeyww » 01 Jun 2023, 08:27

My first question is whether the script that I posted works. That will tell us whether we have a working starting point.

r00173
Posts: 5
Joined: 01 Jun 2023, 05:50

Re: Trying to create a macro, but im bad at coding

Post by r00173 » 01 Jun 2023, 10:12

It works yes

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Trying to create a macro, but im bad at coding

Post by mikeyww » 01 Jun 2023, 10:32

Your first step is deciding which version of AutoHotkey you would like to use. Your second step is writing the script in that version. Would tackle that first. The debugging can then be done. The AHK documentation contains examples of every function, directive, object, and control flow statement, so you can model your code based on the syntax in the examples.

Post Reply

Return to “Ask for Help (v2)”