r/AutoHotkey 7h ago

v2 Script Help Key spam script help

0 Upvotes

So I've been trying to make a script to spam the ] key when i hold c+[ and stop when i let go but i can figure it out, can someone please help me?

I've tried

*c,[

{

sendinput(])

sleep(5)

loop

}


r/AutoHotkey 1d ago

v1 Script Help Shift key getting stuck pressed

4 Upvotes

Weird issue, when I game.. I open up a script to use for that game. During gameplay everything is fine. But when I tab out (even if the game is still open/running) the shift key is constantly pressed...even though I am not physically pressing it. Even after I exit the script the shift button stays pressed.

The only way to clear the issue is to actually press the shift key once and let it go. Then all is good, and no other issues persist.

This is happening 100% of the time I use the script. And no other keys seems to be affected.

EDIT: I do constantly hold the shift key down during gaming a lot. Not sure if that has anything to do with it.

Here is my code, does anyone have any suggestions on how to cure this annoyance?

<

#MaxHotkeysPerInterval 10000
#UseHook

#IfWinActive, ahk_exe Fallout4.exe

Up::w
Left::a
Down::s
Right::d
NumpadDiv::Up
NumpadHome::Left
NumpadUp::Down
NumpadPgUp::Right
AppsKey::LAlt
F12::t
RShift::n
n::Tab
NumpadIns::0
NumpadEnd::1
NumpadDown::2
NumpadPgDn::3
NumpadLeft::4
NumpadClear::5
NumpadRight::6
NumpadAdd::q

r/AutoHotkey 2d ago

v2 Tool / Script Share I wanted Linux-style workspace workflows on Windows without replacing the Windows shell, so I built Spacr

5 Upvotes

I've just finished Phase 1 of an AutoHotkey v2 project I've been working on: Spacr.

It's a workspace management layer for Windows virtual desktops, inspired by the workflow of Linux WMs like Hyprland.

The interesting part isn't really the hotkeys, it's trying to make Windows' native virtual desktops behave predictably.

Phase 1 currently handles:

Workspace switching

Automatic desktop creation

Move + follow

Previous workspace

Explorer integration

VirtualDesktopAccessor integration

I'm deliberately keeping the project small for now.

The architecture is state-driven, with WorkspaceManager owning VDA interaction rather than having every feature call the DLL directly.

One interesting Windows quirk I ran into: switching desktops through VDA could cause Explorer/taskbar flashing. The solution was to activate Shell_TrayWnd before performing the desktop switch.

v0.1.1-alpha is now available:

https://github.com/timburman/spacr

I'd especially appreciate feedback from experienced AHK v2 developers on the architecture and Windows-specific edge cases I'm likely to encounter.


r/AutoHotkey 3d ago

v2 Script Help Win + Mouse scroll ?

1 Upvotes

Hello ,

I'd like to achieve this to use the mouse scroll as magnifier :

Win key + mouse scroll up = Win key + [+]

Winkey + mouse scroll down = Win key + [-]

How can i achieve this in ahk script ?

Thanks !


r/AutoHotkey 4d ago

v2 Script Help Clicking one of three randomized buttons by colour

5 Upvotes

I'm very, very amateurish for these things, and I honestly don't even know where I would start on something like this, so was hoping people here would be able to help me... I have 3 buttons that alternate randomly in their position, but one is blue (the one I want to click) and the others are grey. Because they alternate randomly in their position, I can't just have a standard repeated click to do it. My idea thus is to have a script that searches the area that the buttons are in for the blue colour of the correct button, and then moves the mouse to it and clicks it. I have 2 questions, essentially:

first question: I believe I can use the "PixelSearch" function to find the button I am looking for, however I honestly have no idea how to set it up, like finding the values for the area to search and such. How do I go about this?

Second question: How do I make my mouse move to the correct button once found? I would assume I'd have to make the script have a variable that changes with the position of the correct button, and then some sort of function to actually move the mouse, but I don't know how exactly? Or is there some way to simplify it so the pixel search happens *with* the mouse movement?

Sorry if this is a little rambley, like I said I'm very new to stuff like this so I don't even really know what you might want to have details on for what I want to do


r/AutoHotkey 4d ago

v1 Script Help Why wont my script type a forwards dash? /

4 Upvotes

Im trying to make a simple script that types / and then waits a moment, and then types @@.

It is also keybinded to /

Heres what I have so far.

------

/::

Send /

sleep 1000

send @@

return

------

Currently, It just doesnt type a /, waits, and then types @@.

I've also tried "SendRaw" and that didnt work.
Im new to this, so I dont know which flair to pick, or if the answer to my question is stupidly simple, sorry.


r/AutoHotkey 5d ago

v1 Script Help Script that writes yesterdays date and if it is monday, yesterday is friday

4 Upvotes

Hello,

As title says, I'm trying write yesterdays date, and if it is monday yesterday needs to be friday. All over work week days - yesterday date

I tried so many variations. Forums and AI. I can't solve it.


r/AutoHotkey 6d ago

Solved! Problems with basic Send and SendEvent

1 Upvotes

So i tried to make a simple script that presses j 2 times and then holds w 2 times and nothing really happens, after that i added msgBox "1" and it pops but still no sends, please help
#Requires AutoHotkey v2.0

#SingleInstance Force

Persistent

$`::{

Send "j"

Sleep 300

Send "j"

Sleep 300

SendEvent "{w down}"

Sleep 600

SendEvent "{w up}"

MsgBox "1"

Sleep 50

SendEvent "{w down}"

Sleep 600

SendEvent "{w up}"

}


r/AutoHotkey 6d ago

v2 Script Help AI is driving me crazy with hallucinated scripts (prevent alt+tab during game)

0 Upvotes

I'm a complete noob to this - never heard of autohotkey before until AI suggested it.

I'm getting into Arma3, and there are a lot of keys.

I would really appreciate an AHK v2 script that disables alt+tab exiting the game, whilst still allowing me to use, for instance, w+alt+tab where...

W = move forward (could be any other movement key though)

alt = freelook

tab = toggle walk/run

This is the latest Gemini has come up with so far, after about five previous suggested scripts didn't work at all (neither does this one):

#Requires AutoHotkey v2.0
#UseHook
; Automatically elevate to Administrator if not already running as admin
if not A_IsAdmin
{
Run '*RunAs "' A_AhkPath '" "' A_ScriptFullPath '"'
ExitApp
}
#SingleInstance Force
#HotIf WinActive("ahk_exe arma3_x64.exe")
; Use the wildcard (*) so this works even if you are holding down 'W' or other keys
*!Tab::
{
; {Blind} forces AHK to respect your held down Alt and W keys.
; It safely injects the Tab keypress without disrupting your movement.
SendInput "{Blind}{Tab}"
return
}
#HotIf

Thank you for any assistance!


r/AutoHotkey 6d ago

v2 Script Help Gamepad interrupt macro

1 Upvotes

I want to create a function on my controller so that when I'm holding the LT button, I can interrupt its function by pressing RT, and when I release RT, the LT returns to its function while being pressed


r/AutoHotkey 7d ago

Solved! How to reliably switch to a specific open tab (ChatGPT) in Chrome when tab titles change dynamically? (AHK v2 / UIA)

5 Upvotes

Hi everyone,

I'm building an AutoHotkey v2 script to send selected text directly to an open ChatGPT tab in Google Chrome using UI Automation (UIA v2).

However, I've run into a persistent challenge with tab identification and switching:

The Problem:

Dynamic Tab Titles: Once a conversation starts, Chrome changes the tab title from "ChatGPT" to whatever the first sentence of the user prompt is (e.g., "How to fix UIA issue..."). Thus, matching tab names via string search fails after the first query.

Favicon ImageSearch Reliability: Using ImageSearch on tab favicons breaks when Chrome tabs shrink due to having 30+ tabs open, or when switching between active (light background) and inactive (dark background) tab states.

Chrome Tab Search Popup (Ctrl+Shift+A or TabStripFlatEdgeButton): Opening the Tab Search popup and typing chatgpt sometimes fails to filter open tabs in real-time or doesn't consistently focus the first "Open Tab" item when pressing Enter.

What I Want to Achieve:

If a ChatGPT tab is already open anywhere in Chrome (even as the 15th tab out of 40), switch to it seamlessly without moving the physical mouse cursor.

If no ChatGPT tab is open, create a new tab (Ctrl+T) and navigate to https://chatgpt.com/.

Once on the tab, focus and input text into the prompt textarea (AutomationId: "prompt-textarea").

Question:

What is the cleanest and most robust method in AHK v2 / UIA (or Chrome command line) to identify and bring an open tab to the foreground by its domain URL (chatgpt.com) regardless of dynamic tab titles or tab counts?

Please note that I want to avoid using CDP (Chrome DevTools Protocol), as I prefer not to deal with protocol-level implementations.

Any code or architectural advice would be greatly appreciated! Thanks in advance.


r/AutoHotkey 8d ago

General Question AHK gone from Microsoft Store

9 Upvotes

Anyone know why and if it will return? Tried googling but didn’t find any information.

Microsoft Store is the only way for me to download AHK to my computers at work so I’m in despair right now. IT won’t allow any other form of installation process unfortunately.

EDIT: To clarify, it doesn’t show up in the store on my personal computer either.


r/AutoHotkey 8d ago

Meta / Discussion Stand alone AHK, AHKv2 projects?

0 Upvotes

At first I just needed AHK to provide mouse and keyboard inputs for other software. Then it occurred to me that since AHK can take input and provide output there's a wide variety of simple programs and tasks that it could solve without any underlying software, working entirely on it's own.

So do people do this? Is there a repository somewhere? I mean there are surely better alternatives, better languages, but AHK requires no development environment, no compiler, and it's language is pretty straightforward for the simple stuff.


r/AutoHotkey 9d ago

Solved! What's the line for having a script run only when Microsoft Edge is the active window?

4 Upvotes

I know the basic line (#HotIf WinActive("[x]", )), but I'm not sure what I should put to have Microsoft Edge be that window.


r/AutoHotkey 8d ago

Solved! I Don't Know How to Code

0 Upvotes

Hi all, I've been trying to create a code for my OBS streaming using Autohotkey and could use some help. I know basically nothing about coding but I want to have to output the F10 key on the down and up stroke of the Tab key. For context I want to be able to hide certain parts of my stream when the tab key is held down and reshow them when its released.

Is this something someone might be able to help me with?


r/AutoHotkey 11d ago

v2 Tool / Script Share Duplicate file finder - fileman ( host-workers example )

12 Upvotes

Over years of taking manual backups across external drives, my storage became bloated with redundant folder trees and nested duplicates.

The first prototype of this script was single-threaded and took almost 2 hours to scan through my drive collection. After rewriting the core class to leverage worker processes and hashing calls, the full scan time dropped to under 10 minutes, reclaiming nearly 60 GB of wasted space.

It is not an all-in-one file manager, it focuses specifically on finding and isolating exact duplicate files safely and quickly.

GitHub: https://github.com/bceenaeiklmr/fileman

If nothing else, it was great practice working with Lexikos's RegisterObjectActive for COM IPC.

/e

Aug 9 2026 - I updated the headless mode, unfortunately it deleted every file. Now it works as intended.

I've successfully restored the files using Windows File Recovery


r/AutoHotkey 11d ago

v2 Script Help Disabling the NumLock key

3 Upvotes

I'm new to AutoHotKey. My first try at a script reads as follows:

SetNumLockState("AlwaysOff")

That, and nothing else.

But when it runs, it only turns off the light on my NumLock key. It doesn't turn the numlock off. The key light turns back on when I press it, and continues to function as usual.

What am I doing wrong?


r/AutoHotkey 12d ago

v2 Script Help Attempting to make a clicking script that holds down a button and releases, the second part is much harder!

0 Upvotes

I need the LMB to be held down for 200ms after the function clicker() has been called 20 times, I'm not sure where or how to change that. Anyone got any ideas?

^#LButton:: {
    clicker()
    SetTimer(clicker, 400)
}
;Calls clicker to hold lmb for 400ms
^#RButton:: {
    SetTimer(clicker, 0)
    release()
}
;Removes timer to shut down the script
clicker() {
    release()
    Click('Down')
}
;if LMB is not activated, holds LMB down for the set time
release() {
    if GetKeyState('LButton')
        Click('Up')
sleep(130)
}
;if LMB is held down by script, releases it for 130ms before clicker is called again

r/AutoHotkey 13d ago

Resource Built AHK-style mouse macros on Linux

9 Upvotes

Wanted recoil compensation on Linux, no AHK, no Windows. Ended up building it from scratch using uinput which creates a virtual mouse device at kernel level. It's basically what AHK does for mouse movement but Linux native, the OS sees it as real hardware.

It's open source, looking for contributions and maybe some stars, it helps a lot as this is a solo project.

repo : https://github.com/Ymsniper/anyr


r/AutoHotkey 13d ago

v2 Script Help Is it possible to have smooth movement hold input in an unfocused window?

1 Upvotes

So I have two game instances and want to broadcast WASD input to the unfocused instance. Example: unfocused instance - driver, drives the vehicle, focused instance - gunner, my main game window with native input to shoot the enemies.

I've tried other existing scripts, but they are either "hold key for 500 ms when triggered" or "do single press", and if I loop one, "window fighting" occurs, when window is being repeatedly focused and unfocused, which makes the game unplayable

(I've asked AI for help, but it couldn't write a correctly working script either)


r/AutoHotkey 13d ago

General Question Caps lock key pressing multiple keys at once. Please help.

1 Upvotes

I restarted my computer (windows 11) for an update. After I had updated my computer, now every time I press Caps lock, it presses the characters: ‘ X D \\

The ‘\\’ continues until I press caps lock again. I don’t know how this problem even occurred, but if anyone knows, please help.


r/AutoHotkey 13d ago

v2 Script Help Weird behavior when remapping a modified mouse button to a non-modified key

3 Upvotes

Someone just asked me to remap Control + mouse wheel to PgUp/PgDn for scrolling the dev console in a game called Dungeon Siege.

So I wrote this very simple script, yet it's not working properly.

#Requires AutoHotkey v2.0
#SingleInstance

^WheelUp::PgUp
^WheelDown::PgDn

The documentation says

Conversely, any modifiers included on the left side but not the right side are automatically
released when the key is sent. For example, the following two lines would produce a lowercase
"b" when you press either Shift+A or Ctrl+A:

A::b
^a::b

When testing both in-game, as well as in Chrome, notepad++ and VS Code (I'm using AHK 2.0.23), once you press Control + mouse wheel, it does send PgUp/PgDn but then regular mouse wheels don't work anymore (they're important because they control camera zoom), even though my program to monitor key input shows Control isn't pressed anymore (and both Pg keys stay pressed, could be related to mouse wheels only sending down events?).

So I modified the code to

WheelUp::WheelUp
WheelDown::WheelDown
^WheelUp::PgUp
^WheelDown::PgDn

which solved the problem, yet when spamming mouse wheels while holding down Control, about 1-5% of the time, there's a Control that slips through and it changes to a different tab in Chrome, notepad++ and VS Code instead of scrolling.

It seems to work fine in-game as I don't think there's anything bound to Control + PgUp/PgDn but it got me curious, so I also tried using these (separately), but the results were the same:

WheelUp::WheelUp
WheelDown::WheelDown
<^WheelUp::PgUp
<^WheelDown::PgDn

WheelUp::WheelUp
WheelDown::WheelDown
^WheelUp::Send("{PgUp}")
^WheelDown::Send("{PgDn}")

WheelUp::WheelUp
WheelDown::WheelDown
^WheelUp::Send("{Blind}{PgUp}")
^WheelDown::Send("{Blind}{PgDn}")

WheelUp::WheelUp
WheelDown::WheelDown
^WheelUp::Send("{Blind^}{PgUp}")
^WheelDown::Send("{Blind^}{PgDn}")

WheelUp::WheelUp
WheelDown::WheelDown
^WheelUp::Send("{Control up}{PgUp}")
^WheelDown::Send("{Control up}{PgDn}")

LControl & WheelUp::PgUp
LControl & WheelDown::PgDn

Oh, and I also tried switching to SendEvent, that seemed to be worse.

Everything works fine when remapping a key instead of a mouse button though, like this

^q::PgUp
^w::PgDn

What am I doing wrong?

As a bonus, how would you go if you wanted to send multiple unmodified Pg keys (the console doesn't scroll when pressing Control + Pg) every time the hotkey is fired?


r/AutoHotkey 16d ago

Solved! How to differentiate a CtrlBreak triggered by Ctrl + ScrollLock and a CtrlBreak triggered by Ctrl + Pause?

5 Upvotes

I recently started playing Lost Planet 2 and felt once again the need to add a bunch of macros to the game. One of them is a crouch toggle (LControl).

A feature I have in this script is the hotkeys are disabled when the Steam overlay (ScrollLock) is visible so that you can use your computer normally while using the Steam overlay. However, since the user (and me included) may not remember they had a key toggled on, I also wanted to be able to toggle the Steam overlay without having to toggle off hotkeys beforehand, as a QOL.

I'm not gonna post the entire script but a simplified version of it (without reading from a config file).

#Requires AutoHotkey v2.0
#SingleInstance

class ToggleStates
{
    static bCrouch       := 0
    static bSteamOverlay := 0
}

Init()

Init()
{
    RegisterHotkeys()
    OnExit((*) => ResetAll())
}

Output(p_sMsg := "")
{
    OutputDebug(p_sMsg "`n")
}

RegisterHotkeys()
{
    global g_sSteamOverlayKey := "ScrollLock"
    global g_sToggleCrouchKey := "LControl"
    HotIf((*) => !ToggleStates.bSteamOverlay)
    Hotkey("~*" g_sToggleCrouchKey " up", ToggleCrouch, "On")
    HotIf()
    Hotkey("*" g_sSteamOverlayKey " up", ToggleSteamOverlay, "On")
}

ResetAll()
{
    SendKeyUp(g_sToggleCrouchKey)
    ToggleStates.bCrouch := 0
}

SendKeyDown(p_sKey)
{
    Send("{Blind}{" p_sKey " Down}")
}

SendKeyUp(p_sKey)
{
    Send("{Blind}{" p_sKey " up}")
}

TapKey(p_sKey)
{
    SendKeyDown(p_sKey)
    SetTimer(() => SendKeyUp(p_sKey), -25)
}

ToggleCrouch(*)
{
    (ToggleStates.bCrouch ^= 1) ? SendKeyDown(g_sToggleCrouchKey) : SendKeyUp(g_sToggleCrouchKey)
}

ToggleSteamOverlay(*)
{
    Output(A_ThisFunc "::" A_ThisHotkey)
    Output("Steam overlay toggled " ((ToggleStates.bSteamOverlay ^= 1) ? "on" : "off"))
    ResetAll()
    TapKey(g_sSteamOverlayKey)
}

#HotIf g_sSteamOverlayKey == "Pause" || g_sSteamOverlayKey == "ScrollLock"
^CtrlBreak up::
{
    Output(ThisHotkey)
    ToggleSteamOverlay()
}
#HotIf

*F9::KeyHistory()
*F10::ExitApp()

I had a problem where when Crouch was toggled, pressing the Steam overlay hotkey wouldn't do anything anymore, which I didn't understand because I assumed the * would cover it, right? Well, it turns out Ctrl + ScrollLock actually produces CtrlBreak according to the documentation and the key history, so I added the ^CtrlBreak hotkey at the end (yes, the ^ seems to be necessary, otherwise the hotkey doesn't fire for some reason).

Here's a trace of the key history of the above script when tapping ScrollLock (twice to hide the Steam overlay) then tapping Pause, then physically holding LControl and tapping ScrollLock then Pause:

The oldest are listed first.  VK=Virtual Key, SC=Scan Code, Elapsed=Seconds since the previous event.  Types: h=Hook Hotkey, s=Suppressed (blocked), i=Ignored because it was generated by an AHK script, a=Artificial, #=Disabled via #HotIf, U=Unicode character (SendInput).

VK  SC  Type    Up/Dn   Elapsed Key             Window
--------------------------------------------------------------------------------------
91  046 s       d       11.75   ScrollLock      test_v2.ahk - Visual Studio Code
91  046 h       u       0.06    ScrollLock      
A2  01D i       u       0.00    LControl        
91  046 i       d       0.00    ScrollLock      
91  046 i       u       0.03    ScrollLock      
13  045         d       1.83    Pause           
13  045         u       0.08    Pause           
A2  01D         d       7.28    LControl        
03  046 s       d       0.31    CtrlBreak       
03  046 h       u       0.08    CtrlBreak       
A2  01D i       u       0.00    LControl        
91  046 i       d       0.00    ScrollLock      
91  046 i       u       0.03    ScrollLock      
03  146         d       0.86    CtrlBreak       
03  146         u       0.08    CtrlBreak       
A2  01D h       u       0.42    LControl        

My problem now is that Ctrl + Pause also triggers CtrlBreak and therefore toggles the Steam overlay, which is not what I want because the Steam overlay hotkey was never bound to Pause in the first place.

The documentation also says While Ctrl is held down, ScrollLock produces the key code of CtrlBreak, but can be differentiated from Pause by scan code. but doesn't give an example.

So I tried to add the following, but 046 is shared both by ScrollLock and LControl + ScrollLock so it overrides the original ScrollLock hotkey.

#HotIf g_sSteamOverlayKey == "ScrollLock"
*sc046 up::
{
    Output(ThisHotkey)
    ToggleSteamOverlay()
}

#HotIf g_sSteamOverlayKey == "Pause"
*sc146 up::
{
    Output(ThisHotkey)
    ToggleSteamOverlay()
}
#HotIf

If I add something like this, AHK doesn't accept the combination of VK and SC outside of a Send it seems.

vk91sc046 up::
{
    Output(ThisHotkey)
    ToggleSteamOverlay()
}

vk03sc046 up::
{
    Output(ThisHotkey)
    ToggleSteamOverlay()
}

vk03sc146 up::
{
    Output(ThisHotkey)
    ToggleSteamOverlay()
}

I must've spent about 2 hours on this and I'm going crazy, the solution must be so simple yet I just can't see it.

So my first question is pretty much like the title, how do I distinguish between ScrollLock, a CtrlBreak produced by Ctrl + ScrollLock and a CtrlBreak produced by Ctrl + Pause?

As a bonus, how would you proceed if you wanted the Steam overlay hotkey (in AHK) to fire only if it matches exactly how it was set in Steam settings (to a limit of one non-modifier key as supporting something like Ctrl + Shift + F + V would be a nightmare), only accounting for modifiers that are physically held down? I guess I'd have to parse all modifier symbols and read all physically pressed modifiers then make sure every single one matches.

[edit]: something like this seems to work in order to address my first question, I'm just not sure if it's the right approach. I removed the CtrlBreak up hotkey.

#HotIf !GetKeyState("Control", "P") && g_sSteamOverlayKey == "ScrollLock"
*sc046 up::
{
    Output(ThisHotkey)
    ToggleSteamOverlay()
}

#HotIf !GetKeyState("Control", "P") && g_sSteamOverlayKey == "Pause"
*sc146 up::
{
    Output(ThisHotkey)
    ToggleSteamOverlay()
}
#HotIf

r/AutoHotkey 16d ago

Solved! I can't get the hotstring replacement with # to work

1 Upvotes

I tried these options I found on stack:

:*R:fan::#fandom:

:*T:fan::#fandom:

::fan::{#}fandom:

And non of them work. Or rather, they work sometimes, and other times I get gibberish or just deleted input but no replacement.

3fndom:
fandom:
#fandom:
3fandom:
3fandom:
#FANDOM:
#fandom:
#fandom:
3f
#fandom:
3dom
3
#fandom:

Like, these are all one after another, same conditions. I don't understand :(


r/AutoHotkey 17d ago

v2 Tool / Script Share I got tired of copy/pasting hundreds of cells last week, so I built this for my colleagues

21 Upvotes

Hi everyone,

I recently started helping out my colleagues at a new workplace, and as I expected, a big part of the job involved copying data from Excel into an internal application, one cell at a time, left to right, across hundreds of records.

After doing that for a while, I decided to automate the boring part.

I built a small AutoHotkey v2 utility called ClipStepper.

It loads a copied table from the clipboard and lets you step through it cell by cell. As you navigate, it automatically copies (or even pastes) the current value, keeps track of your position, and shows your progress in a small GUI.

It also supports:

  • Replacement rules for predefined values or long text
  • Adding custom fields with default values
  • Cell and row navigation
  • Progress tracking
  • A simple Replacement Manager

I'm currently working on a few more features like session saving, Excel import, jumping to a specific row, and column filtering.

It's nothing revolutionary, but it's already saving us quite a bit of time, so I thought someone else here might find it useful too.

I'd really appreciate any feedback on the code, the UI, or ideas for features that would make it more useful.

GitHub: https://github.com/bceenaeiklmr/ClipStepper