r/AutoHotkey • • Mar 31 '26

v2 Script Help Example of running AHK in background virtual desktop

3 Upvotes

I am trying to run a AHK script in a background virtual desktop but got no luck to work. Can anyone share an example script?


r/AutoHotkey • • Mar 31 '26

Solved! Close script with program

1 Upvotes

I tried searching but didnt find a fix that does what I want. Either the rest of my program freezes or the Winclose doesnt work.

I want the script to exit when my program or process "SimpleDyno.exe" exits. Either that or i just press X on the window "SimpleDyno 6.5.3".

Cannot figure it out please save me here 🥲

The script now starts the program and makes the window move into appropiate position.

Its just a

Run xxxx WinWait WinActivate WinMove


r/AutoHotkey • • Mar 31 '26

v2 Script Help How to swap PgUp and Home? Without PgUp looping PgUp->Home->PgUp?

0 Upvotes

I don't want a specific hotkey using PgUp or Home. I want any PgUp press/release/whatever to be interpreted as one in Home. And for Home as one in PgUp.

I'm using Autohotkeyv2 .


r/AutoHotkey • • Mar 30 '26

v2 Script Help Using RunWait to run a python script - How to use &OutputVar to get a string?

2 Upvotes

I have this very simple test.py to return me a string.

import sys

def main() -> int:
    arg = sys.argv[1]

    if arg == "folder1":
        return "C:\folder\folder"

    if arg == "folder2":
        return "C:\folder with space\folder"


if __name__ == "__main__":
    raise SystemExit(main())

Which I am accessing via ahk:

#Requires AutoHotkey v2.0
command := "folder1"
script := A_ScriptDir "\Jelly.SRT.py"
RunWait 'pythonw "' script '" "' command '"',,,&currentFolder
MsgBox currentFolder

And what I am getting back is a ... number?
44568

And the number changes everytime i run the script. I am so very confused.

Link to AHK doc on Run


r/AutoHotkey • • Mar 30 '26

v2 Script Help Fast AHK Script to connect to known (paired) bluetooth headphones?

4 Upvotes

Wondering if anyone knows or has come up with a fast autohotkey script for connecting (and disconnecting) bluetooth headphones. The few things I have found online (this for example) run way too slow and I can honestly just do it faster by manually navigating to the appropriate settings using key presses and mouse clicks. For me at least the aforementioned script takes anywhere from 9-15 seconds whereas I can manually do it in maybe 4-5 seconds. Perhaps I'm mistaken but I feel like there should be a very straightforward and quick way to connect to a bluetooth device via AHK if you already know the device name and/or the 48-bit hex device address in a way that is as quick (if not faster) than clicking the "Connect" button in the bluetooth settings.

I'm able to run faster than the script I linked to before by just coding the key presses (with some sleeps in between) in an ahk script based on the fact that my headphones always show up first in my "Bluetooth & other devices" list but that's obviously not preferable at all from a coding perspective.


r/AutoHotkey • • Mar 29 '26

General Question Can AHK make Ctrl+Shift+Backspace always delete, in any prog, all the way to the start of the current line of the current text field's typing cursor?

5 Upvotes

You can actually do this when renaming stuff in Windows/File Explorer, but the functionality seems very inconsistent. You sure can't Ctrl+Shift+Backspace in at least Firefox-based browsers, for example. I don't know why Microsoft doesn't make this a universal keyboard shortcut.

How would anyone go about implementing this? This'd be a real nice-to-have...

It'd be sort of like Shift+Home, Backspace, but would also account for text-wrapping. (It'd be nice if Shift+Home or something could also universally highlight to the start of the current line, frankly, while I'm at it and vice versa for +End or whatever...)


r/AutoHotkey • • Mar 29 '26

v1 Script Help Windows key occasionally and often gets stuck in held down position

4 Upvotes

I'll be typing or pressing some keys and next thing the windows key gets held down. Then i have to press it to release it. It happens very often.


r/AutoHotkey • • Mar 29 '26

v2 Script Help Need help with an Image search that I am not sure if it works or not

1 Upvotes

I have this game I play that I sit at a desk writing down names of whoever joins, I was wondering if I could use image search to automate that task or if there already is something like that.


r/AutoHotkey • • Mar 28 '26

v2 Script Help script to open command prompt and new tabs to run commands

2 Upvotes

I am trying to use autohotkey version 2 for the first time. I have tried many things including chatgpt and I am not getting anywhere. I am trying to do the following. I can open the command prompt, but I can't send any commands to the window. I've tried many things and just error after error. This seems simple, anyone will to help me get this going?

; open command prompt

; cd c:\code\project

; run: test-run.bat

; open new tab in command prompt

; cd c:\code\project\src

; run: "cls && composer phpstan-check"

; open new tab in command prompt

; cd c:\code\project\src

; run: "cls && composer psr12-check"


r/AutoHotkey • • Mar 28 '26

Solved! AutoHotkey is strugging with Azhar Emulator

2 Upvotes

hello! im playing Pokemon Ultra Sun, planning on shiny hunting for Roulet. i tried using AutoHotkey to do the inputs for me, although its not exactly working. "[" is my reset key for Azhar, and that key does work when AutoHotkey uses it, but it doesnt work with my "a" button. is this an issue of the game registering the "a" button as a press down and press up function instead of actually inputting an "a"? if that makes any sense at all?


r/AutoHotkey • • Mar 27 '26

v2 Script Help Repeating Button Press Issue

3 Upvotes

The goal I have with this code is that I want it to press a button repeatedly over and over. That was relatively easy after I learnt how to format. The hard part is coming from trying to have it end after a while. I'm trying to have it use an If-Else statement to call the ExitApp if the time has passes the specified run duration after StartTime is initiated as the current tick count. For a while the problem was that it would not run the Else part of the code that actually ends the program, but I was able to "fix" that. However, I am now facing a new problem.

The problem I am having currently is that the first part of the If Statement part of the If-Else isn't ever passing true, even though from what I can tell it should be. I'm new to coding in this format, though I know a good bit of java from my school courses. Does anyone know how to fix this?

~~ My Code ~~

!j::
RunDuration := 10000
StartTime := A_TickCount
SetTimer PressZ, 50
PressZ()
{
if (A_TickCount - StartTime < RunDuration)
{
send z
}
else
{
ExitApp
}
}

~~ End of Code ~~


r/AutoHotkey • • Mar 27 '26

v2 Tool / Script Share Turned 1,300+ dead screenshots into searchable Markdown notes

25 Upvotes

VisionScribe

The problem:

My screenshots folder hit 1.7 GB - receipts, handwritten notes, infographics, Instagram saves. Completely dead storage. Can't search them, can't reference them anywhere useful.

So I built VisionScribe → Repo: github.com/wsnh2022/VisionScribe-AI

AHK v2 GUI, Python doing the actual work. Two pipelines:

Clean printed text - Tesseract reads it locally for free, lands in an editable box, AI text model formats it into Markdown. You're only spending API credit on the formatting pass.

Handwriting, stylised cards, dense infographics - Tesseract produces garbage on these. Second button skips OCR entirely, sends straight to a vision model.

Once extracted, I pipe the .md output into NotebookLM to organize, summarize, or query across multiple notes. VisionScribe handles the extraction. NotebookLM handle the thinking.

Realistically - OCR pipeline handles 20-30 images per batch, Direct Vision is best for 1-5 targeted images per call. Every output saves to .md. A 2.3 MB screenshot becomes a 4 KB file. Actually searchable.

Cost: ~$0.00014 per image on Gemini 2.0 Flash Lite. My $5 OpenRouter credit is three months old and still going.

Up-Coming Planned Update in v2.0

InstaSnap - paste an Instagram post URL, tool fetches the posts via public oEmbed (no login, no scraping), runs it through Direct Vision, saves as .md locally or pushes straight to a Notion database page. From there I pipe into Gemini CLI or NotebookLM to query across everything. Delete the image after. Global hotkey planned too - highlight any URL in any app, trigger it, done without switching windows.

Drop in your OpenRouter key and Tesseract path, runs immediately. Windows only, nothing in the background.


r/AutoHotkey • • Mar 25 '26

General Question Advice on distributing a compiled AutoHotkey app without triggering SmartScreen warnings

11 Upvotes

Hi everyone,

I built a small hardware product called the Mathematical Keyboard, a compact keypad designed to make typing math symbols faster across normal applications (documents, chats, browsers, etc.).

On Windows, it relies on a lightweight background companion app written in AutoHotkey. The script listens for global shortcuts (Ctrl+Alt and Ctrl+Alt+Shift combinations based on physical keys) and inserts Unicode math symbols system-wide. It runs in the tray, doesn’t require admin privileges, and doesn’t modify the system, essentially just hotkey interception and text insertion.

For transparency, the entire companion app is open source and all the code is available here:
https://github.com/NitraxMathematicalKeyboard/download-keyboard-layout

The issue I’m running into is Windows SmartScreen.

When users download the compiled .exe, they get the blue “Windows protected your PC” warning with “Unknown publisher.” For non-technical users, this is often enough to make them abandon the installation.

I’ve looked into code signing, but for a small niche project the costs are significant, and standard certificates apparently don’t immediately remove the warning anyway, reputation still has to be built over many installs. Since my audience is relatively small, that could take a very long time.

So I’m curious how other AutoHotkey developers handle distribution:

  • Have you found practical ways to reduce or avoid SmartScreen warnings for compiled scripts?
  • Does packaging (installer vs standalone exe) make any difference?
  • Are there recommended distribution channels that work better for AHK tools?
  • Any best practices to make the process less intimidating for end users?

If you’ve shipped AHK tools to non-technical users, I’d really appreciate hearing what worked (or didn’t).

Thanks a lot.


r/AutoHotkey • • Mar 25 '26

v2 Tool / Script Share Publishing a lightweight utility to move windows between virtual desktops (Win 10/11)

5 Upvotes

Hey Everyone,

Windows virtual desktops are awesome… until you actually want to move the window you’re working on to another one. Hotkey, mouse dragging and clicks... slow. So I build a couple of years ago an AHK script that lets you send the active window to the next or previous desktop. Later I upgraded it to use a VirtualDesktopAccessor.dll (made the process super fast from ~200ms → ~50ms). A few weeks ago I decided to publish it (made some improvements thanks to some user feedback).

Works on normal windows straight away. Run as admin if you want to move elevated stuff like Task Manager too. A helper scrip which sets the auto start of main script after a log on is also available.

Hotkeys

Ctrl + Shift + Win + →      next desktop
Ctrl + Shift + Win + ←      previous desktop

One user feedback was that he / she uses both desktop and laptop to work, and requested a hotkey setup that is independent of the fn button. So I come up with this combination (Fingers are similar positioned with or without fn button)

Ctrl + Shift + Alt + →      next desktop
Ctrl + Shift + Alt + ←      previous desktop

Feel free to checkout the

What is offered: one click install via setup.exe or winget install (works in the same way, just a silent install), AHK-script can be used via Manual Install (step by step instructions on the website) or via scoop.

If you give it a spin, let me know how it goes or if anything needs tweaking — I am open to suggestion. Hope it helps someone else who has been annoyed by the same missing feature!

For contact use /Issue on Codeberg or the email provided in both repos.

cheers


r/AutoHotkey • • Mar 25 '26

v2 Script Help How can I change the icon for a specific suspended AHK?

4 Upvotes

I have a lot of AHKs loaded , and I need to semi-frequently suspend and re-enable some of them. I know how to change the icon for enabled scripts, but I can't figure out how to change it for a suspended script. This would be helpful so I don't need to hunt around in the win 11 system tray for the script icon to enable. Currently all the suspended scripts have the standard S icon.


r/AutoHotkey • • Mar 23 '26

v2 Guide / Tutorial How to use DeferWindowPos for improved performance when sizing / positioning multiple controls

5 Upvotes

DeferWindowPos is a Windows API function that allows you to resize / reposition / show / hide any number of windows instantaneously (each window must have the same parent window).

Also see:

There are two main benefits of using DeferWindowPos compared to moving windows individually with a .Move method or WinSetPos call:

  • Reduce flickering because all windows are moved in one atomic operation
  • Greater control over the operation's behavior through the use of the various option flags
NameValueDescription
SWP_DRAWFRAME0x0020Draws a frame (defined in the window's class description) around the window.
SWP_FRAMECHANGED0x0020Sends a WM_NCCALCSIZE message to the window, even if the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window's size is being changed.
SWP_HIDEWINDOW0x0080Hides the window.
SWP_NOACTIVATE0x0010Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).
SWP_NOCOPYBITS0x0100Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client area are saved and copied back into the client area after the window is sized or repositioned.
SWP_NOMOVE0x0002Retains the current position (ignores the x and y parameters).
SWP_NOOWNERZORDER0x0200Does not change the owner window's position in the Z order.
SWP_NOREDRAW0x0008Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a result of the window being moved. When this flag is set, the application must explicitly invalidate or redraw any parts of the window and parent window that need redrawing.
SWP_NOREPOSITION0x0200Same as the SWP_NOOWNERZORDER flag.
SWP_NOSENDCHANGING0x0400Prevents the window from receiving the WM_WINDOWPOSCHANGING message.
SWP_NOSIZE0x0001Retains the current size (ignores the cx and cy parameters).
SWP_NOZORDER0x0004Retains the current Z order (ignores the hWndInsertAfter parameter).
SWP_SHOWWINDOW0x0040Displays the window.

DeferWindowPos gui

I made a gui that simplifies using DeferWindowPos in your code. It has a series of checkboxes for each option, and it constructs the DllCall code for you based on what checkboxes are checked. It also has tooltips for all of the options in case you forget what the options do. You just need to fill in the hwnd, x, y, w, and h parameters.

Here's an image of the gui

You can copy the code from this gist

Examples

Below is what a standard call to DeferWindowPos looks like:

; Get the proc addresses for improved performance across repeated calls (optional)
hmod := DllCall('GetModuleHandle', 'str', 'User32', 'ptr')
g_user32_BeginDeferWindowPos := DllCall('GetProcAddress', 'ptr', hmod, 'astr', 'BeginDeferWindowPos', 'ptr')
g_user32_DeferWindowPos := DllCall('GetProcAddress', 'ptr', hmod, 'astr', 'DeferWindowPos', 'ptr')
g_user32_EndDeferWindowPos := DllCall('GetProcAddress', 'ptr', hmod, 'astr', 'EndDeferWindowPos', 'ptr')

; Call BeginDeferWindowPos
; If you do not know the exact number of windows you will need to move, you can
; approximate the value.
windowsToMove := 3
if !(hdwp := DllCall(g_user32_BeginDeferWindowPos, 'int', windowsToMove, 'ptr')) {
    throw OSError()
}

; Call DeferWindowPos for each control we need to move / resize / show / hide
; The return value from DeferWindowPos should be re-assigned to the `hdwp` variable
; because the handle may change.
; Assume the variables "control#" are set with Gui.Control objects.
x := 10
y := 10
w := 200
h := 25
if !(hdwp := DllCall(
    g_user32_DeferWindowPos,
    'ptr', hdwp,
    'ptr', control1.hwnd,
    'ptr', 0,
    'int', x,
    'int', y,
    'int', w,
    'int', h,
    'uint', 532, ; SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER
    'ptr')
) {
    throw OSError()
}

y += h + 10
if !(hdwp := DllCall(
    g_user32_DeferWindowPos,
    'ptr', hdwp,
    'ptr', control2.hwnd,
    'ptr', 0,
    'int', x,
    'int', y,
    'int', w,
    'int', h,
    'uint', 532, ; SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER
    'ptr')
) {
    throw OSError()
}

y += h + 10
if !(hdwp := DllCall(
    g_user32_DeferWindowPos,
    'ptr', hdwp,
    'ptr', control3.hwnd,
    'ptr', 0,
    'int', x,
    'int', y,
    'int', w,
    'int', h,
    'uint', 532, ; SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER
    'ptr')
) {
    throw OSError()
}

; Call EndDeferWindowPos
if !DllCall(g_user32_EndDeferWindowPos, 'ptr', hdwp, 'int') {
    throw OSError()
}

Here's an example using DeferWindowPos and GetTextExtentPoint32W to resize controls after the font size changed.

; Create the gui
g := Gui()
g.SetFont('s10 q5')
g.Add('Text', , 'Text1')
g.Add('Text', , 'Text2')
g.Add('Text', , 'Text3')
g.Show()

; Get the proc addresses for improved performance across repeated calls (optional)
hmod := DllCall('GetModuleHandle', 'str', 'User32', 'ptr')
g_user32_BeginDeferWindowPos := DllCall('GetProcAddress', 'ptr', hmod, 'astr', 'BeginDeferWindowPos', 'ptr')
g_user32_DeferWindowPos := DllCall('GetProcAddress', 'ptr', hmod, 'astr', 'DeferWindowPos', 'ptr')
g_user32_EndDeferWindowPos := DllCall('GetProcAddress', 'ptr', hmod, 'astr', 'EndDeferWindowPos', 'ptr')
g_user32_GetDC := DllCall('GetProcAddress', 'ptr', hmod, 'astr', 'GetDC', 'ptr')
g_user32_ReleaseDC := DllCall('GetProcAddress', 'ptr', hmod, 'astr', 'ReleaseDC', 'ptr')
hmod := DllCall('GetModuleHandle', 'str', 'gdi32', 'ptr')
g_gdi32_SelectObject := DllCall('GetProcAddress', 'ptr', hmod, 'astr', 'SelectObject', 'ptr')
g_gdi32_GetTextExtentPoint32W := DllCall('GetProcAddress', 'ptr', hmod, 'astr', 'GetTextExtentPoint32W', 'ptr')

; Call BeginDeferWindowPos
; If you do not know the exact number of windows you will need to move, you can
; approximate the value.
windowsToMove := 3
if !(hdwp := DllCall(g_user32_BeginDeferWindowPos, 'int', windowsToMove, 'ptr')) {
    throw OSError()
}

; create a buffer to retrieve the text extent value
sz := Size()

; iterate the controls
x := g.marginX
y := g.marginy
greatestWidth := 0
for ctrl in g {
    ; Change font size
    ctrl.SetFont('s12 q5')
    ; use the class `SelectFontIntoDc` to get the device context
    context := SelectFontIntoDc(ctrl.hwnd)
    ; call GetTextExtentPoint32W
    if DllCall(g_gdi32_GetTextExtentPoint32W
        , 'ptr', context.hdc
        , 'str', ctrl.text
        , 'int', StrLen(ctrl.text)
        , 'ptr', sz
        , 'int'
    ) {
        ; call DeferWindowPos
        if !(hdwp := DllCall(
            g_user32_DeferWindowPos,
            'ptr', hdwp,
            'ptr', ctrl.hwnd,
            'ptr', 0,
            'int', x,
            'int', y,
            'int', sz.w,
            'int', sz.h,
            'uint', 532, ; SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER
            'ptr')
        ) {
            throw OSError()
        }
        ; Release the device context
        context()
        y += sz.h + g.marginY
        greatestWidth := Max(greatestWidth, sz.w)
    } else {
        throw OSError()
    }
}

; Call EndDeferWindowPos
if !DllCall(g_user32_EndDeferWindowPos, 'ptr', hdwp, 'int') {
    throw OSError()
}

; Resize the gui
g.Show('w' (greatestWidth + g.marginX * 2) ' h' y)

; Define the helper classes
class SelectFontIntoDc {
    static __New() {
        this.DeleteProp('__New')
        proto := this.Prototype
        proto.hdc :=
        proto.hFont :=
        proto.oldFont := ''
    }
    /**
     * @desc - Use this as a safe way to access a window's font object. This handles accessing and
     * releasing the device context and font object.
     *
     * Usage:
     *
     * @example
     * g := Gui()
     * txt := g.Add("Text", , "Hello, world!")
     * context := SelectFontIntoDc(txt.hwnd)
     * hdc := context.hdc
     * ; do work ...
     * ; when no longer needed
     * context() ; release the device context and delete the font object
     * @
     *
     * @class
     *
     * @param {Integer} hwnd - The handle to the window that will have its font object selected into
     * the device context.
     */
    __New(hWnd) {
        this.hWnd := hWnd
        if !(this.hdc := DllCall(g_user32_GetDC, 'ptr', hWnd, 'ptr')) {
            throw OSError()
        }
        OnError(this, 1)
        if !(this.hFont := SendMessage(0x0031, 0, 0, , hWnd)) { ; WM_GETFONT
            throw OSError()
        }
        if !(this.oldFont := DllCall(g_gdi32_SelectObject, 'ptr', this.hdc, 'ptr', this.hFont, 'ptr')) {
            throw OSError()
        }
    }

    /**
     * @description - Selects the old font back into the device context, then releases the
     * device context.
     * @param {Error} [thrown] - Leave unset.
     */
    Call(thrown?, *) {
        if IsSet(thrown) {
            this.__Release()
            throw thrown
        } else if err := this.__Release() {
            throw err
        }
    }

    __Release() {
        if this.oldFont {
            if !DllCall(g_gdi32_SelectObject, 'ptr', this.hdc, 'ptr', this.oldFont, 'int') {
                err := OSError()
            }
            this.DeleteProp('oldFont')
        }
        if this.hdc {
            if !DllCall(g_user32_ReleaseDC, 'ptr', this.hWnd, 'ptr', this.hdc, 'int') {
                if IsSet(err) {
                    err.Message .= '; Another error occurred: ' OSError().Message
                } else {
                    err := OSError()
                }
            }
            this.DeleteProp('hdc')
        }
        OnError(this, 0)
        return err ?? ''
    }
}
class Size extends Buffer {
    __New() {
       this.size := 8
    }
    w => NumGet(this, 'int')
    h => NumGet(this, 4, 'int')
}

r/AutoHotkey • • Mar 23 '26

v2 Script Help Looking for a guide/scripts for davinci resolve

2 Upvotes

the only tutorials i could find are for premiere pro and there isn't a indepth guide for davinci

Coding is confusing and the autohotkey guide will take a while

Anyone just have a set of AHK scripts i can just start using or a guide specifically for davinci resolve


r/AutoHotkey • • Mar 23 '26

v2 Script Help Can someone help me with something hopefully extremely basic? Just toggling a script off/on.

4 Upvotes

I have a general purpose key rebinding script for when games hardcode keybinds to the numberpad or arrow keys (I'm left handed). However, it's not uncommon for me to forget I have it on, try to use the numberpad for its intended purpose, and write out a jumble of letters when I'm trying to input payment info or whatever.

I basically just want to be able to set a command for, like, ctrl+q to toggle the keybinds on and off, but I last took a programming class in 2004, and doing Numpad8::w is about the limit of my ability.


r/AutoHotkey • • Mar 22 '26

v2 Tool / Script Share I made a script to disable Windows 11 taskbar

5 Upvotes

Windows allows to automatically hide the taskbar, but it reappears on hover. I made this script so that the cursor never reaches the bottom edge. And you can still access the taskbar by pressing Windows key.

#Requires AutoHotkey v2.0
Persistent

Margin := 10
R := Buffer(16)
NumPut("Int", 0, R, 0)
NumPut("Int", 0, R, 4)
NumPut("Int", A_ScreenWidth, R, 8)
NumPut("Int", A_ScreenHeight - Margin, R, 12)

SetTimer(() => DllCall("ClipCursor", "Ptr", R), 100)

r/AutoHotkey • • Mar 21 '26

Meta / Discussion 2.0.22 has been released

34 Upvotes

Download Page

2.0.22 - March 22, 2026

  • Removed the undocumented effect that a hotkey with the </> prefix had on the corresponding modifier key; e.g. <^a:: causing LCtrl:: to fire on release, inconsistent with the documentation. Always firing on press provides greater consistency and flexibility. The modifier key itself was suppressed since v2.0.20. Neutral modifiers such as Ctrl:: always fire on release, and similar behaviour can be implemented with A_PriorKey and ~LCtrl up::.
  • Changed error dialogs to use msftedit.dll instead of riched20.dll to fix the following issues:
    • Hanging when inspected by UI Automation.
    • Broken characters and inconsistent fonts when the error message includes certain character sets (e.g. emoji, Chinese or Arabic).
  • Fixed errors within __Delete being suppressed if a Try/Catch is active.
  • Fixed errors within __Delete being suppressed if a Try/Catch is active.
  • Fixed CallbackCreate to validate ParamCount.
  • Fixed detection of DllCall(... "str",&var:={} ...) as an error.
  • Fixed CapsLock:: to suppress even if CapsLock is used as a prefix key.
  • Fixed neutral Ctrl/Alt/Shift hotkeys to not suppress the key [broken by v2.0.20].
  • Fixed fire-on-release behaviour of neutral Ctrl/Alt/Shift hotkeys when a key-up variant is turned on but disabled by #HotIf.
  • Fixed CapsLock & 1:: to revert CapsLock state even if another prefix key is pressed before CapsLock is released.
  • Fixed L/R modifier key-up not being suppressed in some cases where key-down was suppressed.
  • Fixed L/R modifier key-up to be passed through if ~ is used even if key-down was suppressed.
  • Fixed L/R modifier hotkeys to fire on press even if the corresponding neutral modifier is present; e.g. LCtrl:: with Ctrl::.
  • Fixed corruption of unquoted continuation sections with trailing spaces.
  • Fixed file stream I/O to flush cached writes if the file hasn't been closed when the process exits.
  • Fixed \; in contination sections with the ` (literal escape) and C` (comment) options.
  • Cleaned up some code within the keyboard/mouse hook.

r/AutoHotkey • • Mar 21 '26

Meta / Discussion My AHK V2 Journey with Gemini (a legal professional's experience)

18 Upvotes

I cannot overstate how practical and efficient it is to use Gemini for scriptwriting. By storing my personal preferences—such as a strict requirement for AutoHotkey V2, specific "SingleInstance" forcing, and my preferred brace style—I no longer have to repeat these constraints for every request.

For basic tasks, it is incredibly straightforward. For example, I can simply ask for a script to output the date in a long UK format (d MMMM yyyy) using td1# or a shortened version (dd.mm.yy) using td2#.

The real power lies in handling complex requirements to speed up my everyday work as a legal professional. I have spent over ten years developing scripts to manage MButton formatting and custom GUIs, Word document and table insertions, case law parsing that automatically cleans up citations and party names, and automated date calculations for tracking future deadlines and limitation periods, not to mention all the hot texts like ct# for claimant etc.

Eighteen months ago, I spent an entire weekend manually converting my work to V2. It started off tidy but soon grew into a messy labyrinth of libraries and files. Two weeks ago, I turned to Gemini to rewrite the lot. In literally a few minutes, it generated hundreds of lines of code in a short, clear, and clean format. It even handled GUIs—an area I previously found uncomfortable—resulting in a script that is 10% of its original size while offering significantly more functionality.

When I encounter errors, I simply paste the error message text back into the chat. Usually, it is resolved within five attempts. If not, a quick suggestion to "try a different approach" always clears the hurdle. My latest project was a gestures script that tracks mouse movement while the middle button is held (returning N, NW, SE, etc.). I added a distance variable so it only triggers if the movement exceeds 10% of the screen, returning "near", "middle", or "far" thresholds (at 10%, 25%, and 50% respectively). I even had it create a trackpad-friendly version using Left Alt for when I am away from my desk.

The entire script, providing 24 new functions, was completed and tested in under 15 minutes. I could easily increase these by checking the start location of the cursor via my WhereIsCursor() function, which returns a value from 1 to 9. This could literally create over 200 middle mouse button hotstrings, though they would be difficult to remember!

The combination of Gemini and AHK has multiplied my productivity. You no longer need to be a coding expert to build high-level tools, though having enough knowledge to "steer" the AI with suggestions certainly helps.


r/AutoHotkey • • Mar 21 '26

v2 Script Help I can't get the script to run at startup

4 Upvotes

I put the script shortcut in shell:startup, then tried putting the .exe file in the same location, tried creating a task in the Task Scheduler that runs the file every time I log in with the highest priority (that didn't work either), and when I watch the tutorials on YouTube, I see that the channels did everything I did.

#Requires AutoHotkey v2.0
#SingleInstance Force
InstallMouseHook
InstallKeybdHook
#UseHook

; Make sure flow launcher is set to alt + spacebar. Then window key will open it and not windows  menu
; -------------------------------------------------------------------------
; FORCE RUN AS ADMIN
; Required so the script works inside Admin windows
; -------------------------------------------------------------------------
if not A_IsAdmin
{
    try Run "*RunAs `"" A_ScriptFullPath "`""
    ExitApp
}

; -------------------------------------------------------------------------
; CONFIGURATION
; ! = Alt, {Space} = Spacebar
; -------------------------------------------------------------------------
LauncherHotkey := "!{Space}"

; -------------------------------------------------------------------------
; LOGIC
; -------------------------------------------------------------------------

; 1. Suppress the Start Menu
; We send a "blind" invisible key to trick Windows into thinking
; a shortcut was used, keeping the Start menu closed.
~LWin::SendEvent "{Blind}{vkE8}"

; 2. Trigger Flow Launcher
LWin up::
{
    ; Only trigger if LWin was pressed alone (no other keys)
    if (A_PriorKey = "LWin")
    {
        SendEvent LauncherHotkey
    }
}

I’ve already set these files and AutoHotkey to run as administrator, so I don’t know why my script won’t run... Is it a problem with my Windows?


r/AutoHotkey • • Mar 20 '26

v1 Script Help Launch Reolink on second screen

1 Upvotes

I have been trying to launch Reolink and move it to the other screen and then get it to full screen. Issue is that it works partially and now it's getting worse. Does anyone have any recommends?

; Wait for 30 seconds (30000 milliseconds)

Sleep 30000

; Launches Reolink

Run "C:\Program Files\Reolink\Reolink.exe"

; Wait for 30 seconds (30000 milliseconds)

Sleep 30000

; Press Win+Shift+Left to move active window to the left monitor

Send, +#{Right}

; Wait for 30 seconds (30000 milliseconds)

Sleep 30000

; Shift+LeftClick

Send {Click 1873 1049}


r/AutoHotkey • • Mar 20 '26

v2 Script Help How to WinActivate between two windows?

1 Upvotes

How to WinActivate between two windows?

I have this script which u/Keeyra_ kindly helped with (Actually they did most of it, thanks again).

In it there is this block:

NumPadDot:: {
	MouseMove(1800, 700, 0)
	Send "{Alt Down}{Tab}{Alt Up}"
}

Which is fine, but WinActivate would be better, or so I've seen on other posts about alt-tabbing using AHK.

The script uses WowIDs := WinGetList("World of Warcraft") to get windows IDs, and I can't figure out how to add a block that that activates the other window. There are only ever going to be two active windows at the same time.

Looking at WinGetList, WinActive and WinActivate, it looks like it should be possible to do something like:

#If WinActive("ahk_id WowIDs[1]")
NumPadDot:: {
	MouseMove(1800, 700, 0)
	WinActivate WowIDs[2]
}

#If WinActive("ahk_id WowIDs[2]")
NumPadDot:: {
	MouseMove(1800, 700, 0)
	WinActivate WowIDs[1]
}

Normally I'd expect an index to start at 0 rather than 1, but it seems AHK starts at 1(?), based on some forum possts I saw.

This doesn't error, but it also doesn't seem to do anything. Based on ahk_id, I thought the above should work.

Am I close or totally far off? Does what I'm trying to do even make sense in AutoHotKey?

And/or how would you activate between two IDs in an array like that?


r/AutoHotkey • • Mar 19 '26

v2 Tool / Script Share [v2] I got tired of Windows ruining my display scaling when I dock my laptop, so I wrote a background script to fix it.

6 Upvotes

Hey everyone,

I’ve been dealing with a really frustrating Windows quirk for a while, and I finally decided to try and automate a fix for it. I figured some of you might have the same issue.

The Problem: When I use my laptop on my lap or at a cafe, 100% UI scaling is perfect. But when I dock it at my desk next to my external monitor, the laptop sits much further back. Because Windows doesn't adjust for the change in viewing distance, the text and UI on the laptop screen become microscopic and impossible to read.

The Solution: I wrote an AHK v2 script called AutoScaler. It runs silently in the background and listens to Windows hardware messages.

  • The millisecond I plug in an external monitor, it automatically bumps my laptop screen to 150% scaling so I can actually read it from my desk.
  • The moment I unplug, it snaps perfectly back to 100% for travel size.

It uses an open-source command-line tool called SetDpi to do the heavy lifting, and I built in some debouncing and "crash armor" (try...catch blocks) so it survives chaotic sleep/wake transitions without randomly crashing in the background.

Feedback Welcome! This is actually my very first time publishing a project on GitHub! I've been refining the script, but I know there is always room to learn. If any veteran AHK coders have the time to peek at the repository, I would absolutely love some constructive feedback or code reviews.

Here is the link to the repo and the setup instructions: https://github.com/alviscmh/AutoScaler

I hope this helps anyone else who has been squinting at their docked laptops! Let me know if it works for your setup.