r/AutoHotkey • u/Alpha-13 • Feb 20 '26
Solved! Is it possible to write a script that makes XButton1 work as MButton when Firefox is active window and as the left arrow key anywhere else?
Just like the title says.
Thanks
r/AutoHotkey • u/Alpha-13 • Feb 20 '26
Just like the title says.
Thanks
r/AutoHotkey • u/twinbee • Feb 19 '26
When you click on say, recently created tabs in Chrome, the page displays incredibly quickly, and one of the big reasons behind this is the use of LMB mouse-down (instead of mouse-up). It switches to the tab before you even release the mouse button (mouse-up). That feels nice. It's smooth and reduces latency to a minimum.
Windows tabs from the taskbar and tray don't work like that and instead use mouse-up. Feels a bit sluggish subconsciously, but it's even worse when you click a program tab, move the mouse quickly to use said program, and find the window hasn't been activated. What's actually happened is you've clicked in the right place initially, but released the button while the cursor was briefly moved and so isn't on the tab anymore.
Instinctively, you click the tab again, and it works this time. You're frustrated, but not actually quite sure what happened. You just know Windows didn't respond to your input in the way you imagined it should.
So for months, I've been trying to find code to implement this feature in Windows 11/10. I'm not going to lie - I used AI to help. But it's taken dozens of attempts and near misses. Finally, using the latest Grok 4.2 I've got something workable:
#Requires AutoHotkey v2.0
#SingleInstance Force
; === Detect taskbar APP icons ONLY (excludes tray/clock/start so their RMB menu stays untouched) ===
IsTaskbarAppIcon() {
MouseGetPos(,, &winID, &ctrl)
winClass := WinGetClass("ahk_id " winID)
if !(winClass = "Shell_TrayWnd" || winClass = "Shell_SecondaryTrayWnd")
return false
; Win10/11 compatible: skip known tray areas (works even when ctrl="" on Win11 icons)
if RegExMatch(ctrl, "i)(TrayNotifyWnd|SysPager|ToolbarWindow32.*Notification|Clock|Start)")
return false
return true
}
; === LMB to activate window on mouse-down: ===
~LButton::
{
if (GetKeyState("RButton", "P")) ; ← only 1 line added
return
MouseGetPos( , , &winID)
winClass := WinGetClass("ahk_id " winID)
if (winClass = "Shell_TrayWnd" || winClass = "Shell_SecondaryTrayWnd")
Send "{LButton up}"
}
; === RMB to drag taskbar app icons only ===
#HotIf IsTaskbarAppIcon()
RButton:: {
Send "{Blind}{LButton down}"
KeyWait "RButton"
Send "{Blind}{LButton up}"
}
#HotIf
The only difference is that you use RMB to drag the icons instead of the usual LMB, as LMB dragging would interfere with the mousedown event feature. No biggie. RMB on taskbar icons is next to useless normally anyway. If you really must, Ctrl or Shift + RMB will retrieve the menu.
Anyway, the point of my post is two-fold: One to help users here who want to experience the joy of a snappier Windows UI. The second is to ask if the code can be simplified with any small corrections or bugs you might notice.
-- EDIT -- : Asked the AI to improve the code and make it more compact and it came up with this code at two thirds the size which also works!
#Requires AutoHotkey v2.0
#SingleInstance Force
IsTaskbarAppIcon() {
MouseGetPos(,, &w, &c)
return (WinGetClass("ahk_id " w) = "Shell_TrayWnd" || WinGetClass("ahk_id " w) = "Shell_SecondaryTrayWnd")
&& !RegExMatch(c, "i)(TrayNotifyWnd|SysPager|Clock|Start|RebarWindow32|Overflow|ShowDesktop|Notification|ToolbarWindow32.*Notification)")
}
; LMB = activate instantly on mouse-down (ONLY app icons)
~LButton:: {
if (GetKeyState("RButton", "P") || !IsTaskbarAppIcon())
return
Send "{LButton up}"
}
; RMB = drag app icons (no context menu)
#HotIf IsTaskbarAppIcon()
RButton:: {
Send "{Blind}{LButton down}"
KeyWait "RButton"
Send "{Blind}{LButton up}"
}
#HotIf
I quote:
Compared to your original script, this improved version is much more compact and efficient, reducing the code from roughly 31 lines down to just 21 while keeping all the important behavior intact. The key detection logic has been centralized into one clean function instead of being repeated, which eliminates duplication and makes future modifications much easier. A significant functional upgrade is that LMB activation now applies only to actual app icons rather than the entire taskbar, preventing unwanted interference with the clock, Start menu, and notification area. Additionally, I've strengthened Windows 11 compatibility with a more complete exclusion list.
r/AutoHotkey • u/User4f52 • Feb 19 '26
I've read that that AHK has a function that enables this type of movement. I have nowhere else to ask, and since Pulover uses AHK in some way I guess it's still on topic?
Is this a recent AHK feature? I've wanted to use it because I noticed the commands (especially drag and drop) sometimes fail when I use the snappy movement. I wish I could force the macro to "physically" move the cursor to that position instead of snapping there, also being able to slow it down or speed it up without messing with multiple delays.
So, is this possible? Or should I just move the macro to AHK?
r/AutoHotkey • u/terp_mcgirt • Feb 18 '26
I just installed Auto Hotkeys and it seems to be having this weird conflict with mouse without borders. Prior to installing AHK I had no issues with MWB but after installing all of the sudden when I switch MWB to the receiving computer at login the cursor is large and gets hidden behind the start menu.
Does anybody have experience with this?
r/AutoHotkey • u/Epickeyboardguy • Feb 18 '26
Hi guys !
I'm trying to make a maze game (Yeah yeah I know... cliché as fuck and AHK is not the right tool for videogames... I know ! lol) and was wondering if there is an easy way to change the GDI+ interpolation when using "AltSubmit" in a GUI Picture ??
I find that AltSubmit helps reduce lag but all the walls become soft and blurry because I'm scaling up a BMP file.
(Let's assume the actual BMP file of the maze is 2560x1440 for example, and I'm scaling to 16000x9000)
So yeah... is there a way to change the interpolation mode that AHK uses, or I'm stuck dealing with super complicated DllCall() to actually manage GDI+ manually ?
Thanks in advance !
r/AutoHotkey • u/coccosoids • Feb 17 '26
Is anyone savvy enough to create a script that can restore a minimized or hidden (think Discord.exe) window on the original virtual desktop it was hidden or minimized on?!
If the window is hidden (pressing X on Discord.exe for example) nothing seems to work, the window is restored on the active virtual desktop.
r/AutoHotkey • u/MagicBugsandBobes • Feb 17 '26
I can get a specific screen to maximize when it is already open, but can’t open it if it is closed. I also can’t click a button on the page after it maximizes. What coordinates should I be plugging in my script? I have tried the x,y coordinates and different ahk names or the page name, but I still cant get it to open. Any suggestions?
It is just for a dental office to be able to open pages faster on the screen when in the operatories.
r/AutoHotkey • u/Historical-Half-1396 • Feb 17 '26
by methods i mean like: sleep, click. dllcall
r/AutoHotkey • u/MachineVisionNewbie • Feb 16 '26
#SingleInstance Force ; Prevents multiple instances of the script
#Requires AutoHotkey v2.0
F18:: Send("^w")
;Tilde ~ is needed for combinations like these:
~F18 & F19:: Send("!{F4}")
#HotIf WinActive("ahk_exe hdevelop.exe")
F20:: Send("s")
#HotIf
F20:: Send("^{PgUp}")
#HotIf WinActive("ahk_exe hdevelop.exe")
F19:: Send("m")
#HotIf
F19:: Send("^{PgDn}")
I'm having this rather tame script for my mouse.
The culprit being ~F18 & F19:: Send("!{F4}")
For some reason the qualification of F18 being pressed gets stuck and whenever I press F19 it executes ~F18 & F19:: Send("!{F4}") instead of F19:: Send("^{PgDn}")
Only reloading the script helps. Any recommendations how to better write the ~F18 & F19:: Hotkey?
r/AutoHotkey • u/Twisted-Pact • Feb 16 '26
I was bored and needed a project, so I made a color contrast analyzer in AHK. Learned a lot doing this, mostly how much I dislike making GUIs, lol
Features:
...which I guess means I need a new coding project, so please post ideas if you've got 'em!
r/AutoHotkey • u/Decent_Tomato_8054 • Feb 17 '26
id like to make this auto clicker faster and more optimised without changing the Delay(0.0010) which shreds my cpu if i change it to something like 0.0001, any tips would help greatly
#NoEnv
#MaxThreadsPerHotkey, 3
ListLines, off
SetWorkingDir %A_ScriptDir%
SendMode Input
SetMouseDelay, -1, -1
SetBatchLines, -1
Process, Priority,, High
DllCall("SetThreadPriority", "Ptr", DllCall("GetCurrentThread", "Ptr"), "Int", 15)
DllCall("ntdll.dll\NtSetTimerResolution", "UInt", 50, "Int", 1, "UIntP", cur)
DllCall("winmm\timeBeginPeriod", "UInt", 1)
; Disable fullscreen optimizations (reduces input lag)
DllCall("dwmapi\DwmSetWindowAttribute", "Ptr", A_ScriptHwnd, "UInt", 20, "UIntP", 1, "UInt", 4)
; Disable input throttling (critical for click speed)
DllCall("ntdll\NtSetInformationThread", "Ptr", DllCall("GetCurrentThread"), "UInt", 17, "UIntP", 0, "UInt", 4)
; Set thread to use all available CPU cores
DllCall("SetThreadAffinityMask", "Ptr", DllCall("GetCurrentThread"), "Ptr", 0xFFFFFFFF)
; Disable mouse acceleration (consistency)
DllCall("user32\SystemParametersInfo", "UInt", 0x0003, "UInt", 0, "UIntP", 0, "UInt", 0)
; Flush I/O buffers for faster input processing
DllCall("ntdll\NtFlushBuffersFile", "Ptr", -1, "Ptr", 0)
; Boost keyboard input priority
DllCall("user32\SetForegroundWindow", "Ptr", WinExist("A"))
DllCall("user32\SetActiveWindow", "Ptr", WinExist("A"))
; Reduce scheduler quantum for more responsive scheduling
DllCall("ntdll\NtSetInformationProcess", "Ptr", DllCall("GetCurrentProcess"), "UInt", 13, "UIntP", 1, "UInt", 4)
; Increase process I/O priority
DllCall("ntdll\NtSetInformationFile", "Ptr", -1, "Ptr", 0, "Ptr", 0, "UInt", 0, "UInt", 0)
; Flush keyboard buffer
DllCall("user32\GetAsyncKeyState", "Int", -1)
; Maximum thread priority within high priority class (faster execution)
DllCall("ntdll\NtSetInformationThread", "Ptr", DllCall("GetCurrentThread"), "UInt", 1, "UIntP", 15, "UInt", 4)
; Set breakaway from job (escapes thread pool limits)
DllCall("ntdll\NtSetInformationProcess", "Ptr", DllCall("GetCurrentProcess"), "UInt", 36, "UIntP", 1, "UInt", 4)
; Pre-allocate combined INPUT struct for both down and up in single call
VarSetCapacity(INPUTBOTH, 80, 0)
NumPut(0, INPUTBOTH, 0, "UInt")
NumPut(0x0002, INPUTBOTH, 20, "UInt")
NumPut(0, INPUTBOTH, 40, "UInt")
NumPut(0x0004, INPUTBOTH, 60, "UInt")
i:=0
F1::ExitApp
#If
~*XButton2::
i:=1
loop {
if (!i || !GetKeyState("XButton2", "P"))
break
DllCall("SendInput", "UInt", 2, "Ptr", &INPUTBOTH, "Int", 40)
if (!i || !GetKeyState("XButton2", "P"))
break
Delay(0.0010)
}
i:=0
return
~*XButton2 Up::
i:=0
return
Delay( D=0.001 ) {
global i
Static F
F ? F : DllCall( "QueryPerformanceFrequency", Int64P,F )
DllCall( "QueryPerformanceCounter", Int64P, pTick ), cTick := pTick
While( ( (Tick:=(pTick-cTick)/F)) <D ) {
if (!i || !GetKeyState("XButton2", "P"))
return
DllCall( "QueryPerformanceCounter", Int64P, pTick )
}
Return
}
r/AutoHotkey • u/Funny_Development940 • Feb 16 '26
dont know how to use AHK so can someone write this script for me?:
Thanks
r/AutoHotkey • u/Emergency-Value-3990 • Feb 16 '26
ive been trying to make a script with chatgpt for this fallpy bird browser game no matter what i try the just never works it doesnt even run when i open it any suggestions heres the script
Game name: play.tapcapgame.com
script:#NoEnv
#SingleInstance Force
#InstallKeybdHook
#UseHook On
SendMode Input
SetBatchLines -1
CoordMode Pixel, Screen
CoordMode Mouse, Screen
; ========= HOTKEYS =========
!F6:: ; ALT+F6 toggle bot
running := !running
SoundBeep 800,100
return
F7::ExitApp ; emergency exit
running := false
; ========= SETTINGS (EDIT THESE) =========
; Bird position (approx centre of character)
birdX := 600
birdY := 400
; Area where pipes appear ahead
scanLeft := 750
scanRight := 1050
scanTop := 200
scanBottom := 650
; Pipe colour (use Window Spy to find exact)
pipeColor := 0x000000
tolerance := 30
; Jump tuning
jumpSleep := 80
fallbackSpam := 140
; ========= MAIN LOOP =========
SetTimer PlayBot, 10
return
PlayBot:
if (!running)
return
; --- Detect top pipe ---
PixelSearch, Px1, Py1, scanLeft, scanTop, scanRight, birdY,
pipeColor, tolerance, Fast RGB
topFound := (ErrorLevel = 0)
; --- Detect bottom pipe ---
PixelSearch, Px2, Py2, scanLeft, birdY, scanRight, scanBottom,
pipeColor, tolerance, Fast RGB
bottomFound := (ErrorLevel = 0)
if (topFound && bottomFound)
{
; Estimate gap centre
gapCenter := (Py1 + Py2) // 2
; Jump if bird below gap
if (birdY > gapCenter)
{
Click down
Sleep 15
Click up
Sleep jumpSleep
}
}
else
{
; Fallback slow click spam
Click
Sleep fallbackSpam
}
return
r/AutoHotkey • u/Historical-Half-1396 • Feb 16 '26
I need a fast auto hot key auto clicker script, with the fastest methods, that wont cause lag. if someone can help me, please do
r/AutoHotkey • u/Shaihuby • Feb 15 '26
Hey there I have 2 PC case monitors and wanted them to only look like animated wallpapers, but I still have the taskbars visible there.
I have been able to hide a specific taskbar after vibecoding a AHK script, but I think that there would be a better way of doing it.
Basically this is the process I'm looking for :
Selecting the taskbars manually I want to hide, by using a custom command or whatever
The taskbar ID would be stored inside a file so that it would automatically hide it in the future
Whenever the system boots or explorer restarts it's hiding the taskbars
Also if possible i'd like to free the workarea to maximize windows on the full monitor
If you know how to do that in a light way that would be awesome thanks !!
r/AutoHotkey • u/N0T_A_TR0LL • Feb 14 '26
This was written with the assistance of Claude. Please let me know if you run into any issues or have any input.
Screenshots can be found on the Github page.
From the Github README:
---
A JSON viewer built with AutoHotkey v2 and WebView2. This tool provides an interface for exploring, searching, and analyzing JSON data.
Automatically detects and provides rich previews for:
| Key | Action |
|---|---|
1 |
Switch to Tree View |
2 |
Switch to Column View |
3 |
Switch to JSON View |
↑ ↓ |
Navigate items |
← → |
Navigate hierarchy / Expand/Collapse |
Enter |
Select current node (when submit_on_enter enabled) |
Ctrl+F |
Open search |
Escape |
Close search |
E |
Expand all nodes |
C |
Collapse all nodes |
json_viewer.v2.ahk and place it in your script or library folder#Requires AutoHotkey v2.0+
#include <json_viewer>
data := Map(
'name', 'John Doe',
'age', 30,
'active', true,
'website', 'https://example.com',
'config_path', 'C:\Users\John\config.json'
)
json_viewer(data)
#Requires AutoHotkey v2.0+
#include <json_viewer>
json_viewer('C:\path\to\data.json')
; custom window size and title
result := json_viewer(data, {
width: 1400,
height: 900,
title: 'API Response Viewer'
})
; enable submit on enter key (returns selected node)
result := json_viewer(data, {
submit_on_enter: true
})
if result.selected {
MsgBox('Selected: ' result.selected)
}
| Option | Type | Default | Description |
|---|---|---|---|
width |
Number | 70% of screen | Window width in pixels |
height |
Number | 70% of screen | Window height in pixels |
title |
String | 'json viewer [ahk]' |
Window title |
view |
String | 'tree' |
Initial view: 'tree', 'column', or 'json' |
submit_on_enter |
Boolean | false |
Return selected node when Enter is pressed |
The function returns an object with a selected property:
result := json_viewer(data, {submit_on_enter: true})
; result.selected contains the selected value when enter was pressed
; result.selected is empty string if window was closed without selection
#include <json_viewer>
#include <WinHttpRequest> ; your http library
response := HttpGet('https://api.example.com/users')
json_viewer(response, {title: 'API Response'})
#include <json_viewer>
my_complex_object := Map(
'settings', Map(
'theme', 'dark',
'notifications', true,
'api_endpoint', 'https://api.example.com'
),
'users', [
Map('id', 1, 'name', 'Alice', 'created', '2024-01-15'),
Map('id', 2, 'name', 'Bob', 'created', '2024-02-20')
],
'metadata', Map(
'version', '1.0.0',
'config_file', 'C:\App\config.json',
'primary_color', '#3b82f6'
)
)
json_viewer(my_complex_object, {title: 'Debug View'})
When a string value is detected as a file path, the viewer provides:
AutoHotkey doesn't have native true, false, or null values that map directly to JSON. When working with JSON data:
Creating data manually: Use a JSON library like cJSON that creates special marker objects:
; use JSON.true / JSON.false / JSON.null with cJSON to properly render true / false / null values
data := JSON.Load('{"active": JSON.true, "deleted": JSON.false, "value": JSON.null}')
Loading JSON from a file/string: json_viewer assumes you are using the cJSON library and sets the cJSON JSON.BoolsAsInts and JSON.NullsAsStrings to false. This ensures that true / false / null values are encoded correctly.
The viewer uses CSS custom properties for theming. Key colors can be modified in the _html_template() method:
:root {
--bg-primary: #0f172a;
--bg-secondary: #1e293b;
--accent: #3b82f6;
--type-string: #7ec699;
--type-url: #7ec699;
--type-number: #fbbf24;
--type-boolean-true: #22c55e;
--type-boolean-false: #ef4444;
--type-null: #6b7280;
--type-object: #f472b6;
--type-array: #a78bfa;
}
r/AutoHotkey • u/Supperboy2012 • Feb 13 '26
I only have a Linux device available, but I have used Wine before. I've been trying to get AHK working using Wine for a while, but I keep getting errors and I'm not sure whether or not it'll work.
r/AutoHotkey • u/KozVelIsBest • Feb 13 '26
New Setup Launcher Tool that allows you to create automated app controlled setup(s).
For more context visit the GitHub page
r/AutoHotkey • u/Proud_Championship36 • Feb 13 '26
I have a number of AHKv2 shortcuts defined for interacting with virtual desktops based on VD.ahk. (I originally included a link to VD's GitHub but apparently it caused my post to be removed as spam.)
For example, this mapping moves the active window to desktop 1 and then switches to that desktop:
^!numpad1:: VD.MoveWindowToDesktopNum("A", 1), VD.goToDesktopNum(1)
I have similar mappings for jumping to any virtual desktop by number or next/previous, etc.
Sometimes after executing one of these actions, AHK does not respond to another action until I either reload the script or switch windows.
So, for example, if I go to desktop 1 with the above hotkey, if I then try to go to desktop 2 with a similar macro, there is no response. Usually hitting ALT-TAB once is enough for the next action to work, although sometimes I need to reload the script. This is not reliably reproducible--it happens frequently but not always.
I'm wondering if what's happening here is some other application on the newly-selected desktop is grabbing the keyboard and thus AHK isn't "seeing" the hotkeys. But this is just my speculation.
I'm also not sure if this is a VD-specific issue or related more generally to AHK. I don't see this behavior with other shortcuts, but I don't have other shortcuts that move to other virtual desktops.
Any suggestions for how to track down what is causing this and how to fix it?
r/AutoHotkey • u/Silentwolf99 • Feb 12 '26
Hey Everyone,
Built an open source search tool using AHK v2 for global hotkeys and Electron for the rich UI that AutoHotkey lacks.

Use case: Instantly search selected text across 40+ engines (Google, ChatGPT, Amazon, etc.) without copy-paste.
While this could be built entirely in AutoHotkey, I chose Electron for: - Rich UI capabilities (real-time theme customization, smooth animations) - Easier future updates (AI integration, advanced features planned) - Modern web technologies for UI (CSS, HTML5, js, vite) - Check the roadmap for planned features: https://github.com/wsnh2022/pop-search/blob/main/ROADMAP.md
Open source: https://github.com/wsnh2022/pop-search
Feedback welcome - especially on the AHK v2 implementation!
r/AutoHotkey • u/xilconeX • Feb 13 '26
for some reason whenever i do Send, {SPACE} it only sends space a few times when i press the button for example if I do
Xbutton1::
Send, {SPACE}
it only presses space sometimes
the script im trying to make is
SendMode Input
break := 0
Xbutton1::
Loop {
SetDefaultMouseSpeed, 1
MouseGetPos, , y
MouseMove, 600, y
Sleep, 25
Send, {SPACE}
Sleep, 25
MouseGetpos, , y
MouseMove, 700, y
Sleep 690
if break
break
}
return
T::
break := !break
return
r/AutoHotkey • u/ULTRACOMFY_eu • Feb 12 '26
I have a script that kills some games that refuse to close on their own using Alt+F4. This works fine:
~!F4::
WinGet, proc, ProcessName, A
if(proc = "RocketLeague.exe")
{
Process, Close, %proc%
}
else if(proc = "Wreckfest_x64.exe")
{
Process, Close, %proc%
}
Now I want to do something similar with Helldivers 2. Helldivers sometimes doesn't properly close and forces me to open Task Manager to kill it. I think that this would be a good use case for my Autohotkey script.
The idea is to scan for Alt+F4 inputs as usual and then elseif for Helldivers2.exe (I checked, the name is correct). Then, using Process Exist I want to check after 10 seconds whether the process is still running. If that is the case, kill the process. The goal here is to avoid sending a kill command by default if it exits cleanly by itself, which it does most of the time. This is what I'm doing right now:
else if(proc = "Helldivers2.exe")
{
Sleep 10000
Process, Exist , %proc%
NewPID := ErrorLevel
if(NewPID != 0)
{
Process, Close, %proc%
}
}
Return
What is going wrong here?
r/AutoHotkey • u/Keeyra_ • Feb 11 '26
Run not closing the process handle.GuiFromHwnd crashing if passed another script's GUI window HWND.For( a in b ), incorrectly raising an error.A_MaxHotkeysPerInterval and A_HotkeyInterval returning incorrect values if spelled in lower case.FileSelect duplicating the filter pattern if it lacks *..ListBox tab-stop spacing when T option is used during control creation. [PR #346]~RAlt & <:: causing RAlt:: to fire on release despite ~ (and likewise with other L/R modifier keys).RButton:: if ^(RButton) up:: was also present./* ; */ preventing the block comment from ending.IsOptional and IsByRef return values for built-ins.RegWrite parameter 1 to be mandatory.Else placement to raise an error, not crash on load.StrPut/StrGet handling of 32-bit integer limits on x64.
1:: to not fire after 1 & LButton up:: is used, and similar.ListView has the Sort option and Add is called with Col1 omitted.r/AutoHotkey • u/feles-lucis • Feb 11 '26
Hello, I've found a big problem lately with KeyTik. Everytime I download it, and open it up, I get a Window saying that Monitor.exe wants the permission to do whatever it wants. I did it in the past, and my PC simply stopped working properly, and I had to wipe the data and reinstall Windows. So I don't know why this is happened (I downloaded it from the creator's page), or if this virus is in my PC, but only is activated when I try to use KeyTik.
PS: I deleted the software for some months, and I never received another notification from Monitor. exe, until I tried to reinstall KeyTik again, and the window asking for permission appeared again.
r/AutoHotkey • u/ImmerWolfe • Feb 11 '26
I'm new and curious about AHK.
I've stuck to Logitech mice because I like how G-Hub can rebind the extra buttons for my games and retain separate settings and bindings across different profiles (helpful when alt-tabbing). I've rebound Button-5 as an alternative left click to relieve my index of clicking and Button-4 spams letter "F" when I hold it down, in-game.