r/AutoHotkey

Switching Middleclick Mouse button to Shift+Rightclick not working

Switching Middleclick Mouse button to Shift+Rightclick not working .

Try closing a webbrowser opentab which closes with mouse Middleclick.

1 Attempt One

#Requires AutoHotkey v2.0

+RButton::ToolTip "Mouse Shift+RightClick detected but Mbutton not executed"

+RButton::Send "{MButton}"

  1. Attempt Two

    #Requires AutoHotkey v2.0

    RButton:: { if GetKeyState("Shift", "P") Send "{MButton}" else Send "{RButton}" }

    3.Attempt Three #Requires AutoHotkey v2.0

    #HotIf GetKeyState("Shift","P") RButton::Send "{MButton}"

    #HotIf RButton::Send "{RButton}"

reddit.com
u/gripped909 — 14 hours ago

Spamming right click with a modifier key.

I am trying to write what I thought was a very simple script.

While holding down backtick, ` i.e., vkC0, I want it to keep CTRL held down and spam right click. However, I always run into problems where either CTRL gets stuck held down, or the script keeps spamming after letting go of the key.

I have tried so many common variants using GetKeyState or keywait, but nothing seems to help.

One suggestion was to use this pattern:

~a::
	tooltip A PRESSED
	return

~a up::
	tooltip A RELEASED
	return

instead, but that still doesn't seem to work.

I've similarly found a comment that suggested this is the best pattern:

a::
	if (a_pressed)
		return
	a_pressed := 1
	; [...]
	return

a up::
	a_pressed := 0
	return

but it doesn't work for me either. This is a sample attempt in (which isn't ideal because I would prefer CTRL be held down the whole time I hold backtick down).

vkC0_pressed := 0

*vkC0::
    if (vkC0_pressed)
        return
    
    vkC0_pressed := 1
    SetTimer, SendRightClick, 50
return

*vkC0 up::
    SetTimer, SendRightClick, Off
    vkC0_pressed := 0
return

SendRightClick:
    SendInput ^{RButton}
return

There are other attempts, but I have so many failed attempts that I have completely lost track at this point. I have tried numerous variations of this in v1 and in v2, but I would prefer a v2 solution.

reddit.com
u/chaneg — 2 days ago

#IfWinActive active window name

i'm pretty new to this and i wanted to ask some question since i only find error in 30min, i want to make it so that i can use my right click work just like my left click on certain window.

#Requires AutoHotkey v2.0

#IfWinActive, MSI App Player
RButton::LButton
#IfWinActive

it's pretty much copy pasted from other reddit post, i only changed the window name but not sure if it's correct. so i open window spy and i got this for the windows title, class and process:

MSI App Player
ahk_class Qt672QWindowIcon
ahk_exe HD-Player.exe
ahk_pid 11828
ahk_id 331062

so can someone points out what's my mistake is and how to fix it?

thanks in advance

reddit.com
u/novian14 — 2 days ago
▲ 0 r/AutoHotkey+1 crossposts

Aseprite, Godot AND, Blender with a profile swap on the X15 mouse

#Requires AutoHotkey v2.0

; --- CODE ENGINES & ALIASES ---

S(keys) => Send(keys)

; Universal Hold Engine: Handles the down/up locking logic for any keys cleanly

Hold(physicalKey, keysToSend*) {

for key in keysToSend {

Send("{" key " Down}")

}

KeyWait(physicalKey)

for key in keysToSend {

Send("{" key " Up}")

}

}

; =========================================================================

; COLOR PROFILE CONFIGURATION

; =========================================================================

global ActiveProfile := 1

global MyCustomToolTip := Gui("-Caption +AlwaysOnTop +ToolWindow")

MyCustomToolTip.BackColor := "000000"

MyCustomToolTip.SetFont("cFFD700 s10 Bold", "Segoe UI")

global ToolTipText := MyCustomToolTip.Add("Text", , "Profile 1: Modeling (#FF0000)")

; =========================================================================

; BLENDER INTERFACES & SUB-PROFILES

; =========================================================================

#HotIf WinActive("ahk_exe blender.exe")

F24:: {

global ActiveProfile

ActiveProfile := ActiveProfile + 1

if (ActiveProfile > 3) {

ActiveProfile := 1

}

message := ""

if (ActiveProfile == 1)

message := " Profile 1: Modeling (#FF0000) "

else if (ActiveProfile == 2)

message := " Profile 2: Animation (#00FF00) "

else if (ActiveProfile == 3)

message := " Profile 3: Texturing (#0000FF) "

ToolTipText.Value := message

MyCustomToolTip.Show("X20 Y20 NoActivate")

SetTimer(() => MyCustomToolTip.Hide(), -2000)

}

; --- BLENDER PROFILE 1 (MODELING) ---

#HotIf WinActive("ahk_exe blender.exe") and (ActiveProfile == 1)

F13::S("e") ; [Button 1] Extrude

F14::S("{WheelUp}") ; [Button 2]

F15::S("{WheelDown}") ; [Button 3]

F18::S("^r") ; [Button 6] Loop Cut

F19::Tab ; [Button 7] Native Tab Hold

; --- BLENDER PROFILE 2 (ANIMATION) ---

#HotIf WinActive("ahk_exe blender.exe") and (ActiveProfile == 2)

F13::S("i") ; [Button 1] Insert Keyframe

F14::S("!a") ; [Button 2] Play/Pause

; --- BLENDER PROFILE 3 (TEXTURE PAINT) ---

#HotIf WinActive("ahk_exe blender.exe") and (ActiveProfile == 3)

F13::S("s") ; [Button 1] Sample Color

F14::S("x") ; [Button 2] Swap Colors

; =========================================================================

; GODOT ENGINE PROFILE

; =========================================================================

#HotIf WinActive("ahk_exe Godot_v4.x-stable_win64.exe")

F13::S("^s") ; [Button 1] Save Scene

F14::S("{F5}") ; [Button 2] Run Project

; =========================================================================

; ASEPRITE PROFILE

; =========================================================================

#HotIf WinActive("ahk_exe Aseprite.exe")

F13::Hold("F13", "Alt", "Left") ; [Button 1] Clean Hold for Alt+Left!

F14::S("{WheelUp}") ; [Button 2]

F15::S("{WheelDown}") ; [Button 3]

F16::S("{Enter}") ; [Button 4]

F17::S("b") ; [Button 5] Brush Tool

F18::S("e") ; [Button 6] Eraser Tool

F19::S("{<}") ; [Button 7]

F20::S("{>}") ; [Button 8]

F21::S("9") ; [Button 9]

F22::S("0") ; [Button 10]

F23::Ctrl ; [Button 11] Native Control Hold

; =========================================================================

; GLOBAL KILL SWITCH

; =========================================================================

#HotIf

^+Esc::ExitApp

reddit.com
u/Geofernis — 4 days ago

Having variable scoping problems using functions

I'm trying to make a pop-up menu that calls various functions to do stuff, but seem to be having variable scoping problems. The command "MyMenu.Hide()" in the first function generates the error: "Global variable has not been assigned a value". Adding "global MyMenu" before it didn't help. Thanks in advance.

   #Requires AutoHotkey v2.0
   #SingleInstance Force
   ; Example showing a 3-button menu. 
   ; Press Windows Key + "/" to activate menu. Pound-sign means Windows-key.
   #/:: {
       MyMenu := Gui(, "Keystroke Menu")
       MyMenu.Opt("+AlwaysOnTop") ; Keeps menu visible
       ; Add buttons to the menu
       MyMenu.Add("Button", "w180", "Send Email Sign-off").OnEvent("Click", SendSignOff)
       MyMenu.Add("Button", "w180", "Send Date &amp; Time").OnEvent("Click", SendDateTime)
       MyMenu.Add("Button", "w180", "Send Select All &amp; Copy").OnEvent("Click", SendCopyAll)
       MyMenu.Show()
   }
   ; Function to hide menu
   HideMenu() {
       global MyMenu   ; added, but didn't help
       MyMenu.Hide()   ; PROBLEM LINE
       Sleep(100)      ; Wait for focus to return to document
   }
   ; Function for Button 1
   SendSignOff(GuiCtrlObj, Info) {
       HideMenu() ; Hide menu first
       SendInput("Best regards,{Enter}John Doe")
   }
   ; Functions for Button 2 &amp; 3 not shown
reddit.com
u/Zardotab — 5 days ago

How to skip ahead in a long script with hotkeys?

I have recorded this very long script with Feiyue's macro recorder to autofarm a game. I have noticed that sometimes the script fails due to latency or other issues. I want to add hotkeys where I can skip ahead to certain parts of the script so it can continue autofarming past areas it already completed.

I have tried Goto with labels, but get this error message "A Goto/Gosub must not jump into a block that doesn't enclose it".

Is there an easy way to implement this without having to change my script into alot of functions? Or perhaps I need to separate all the regions into their own functions, and call them in the main loop.

Really appreciate any feedback. Thanks.

This is a gist of my script so far

Playspeed:=1 

Loop, 1
{
SetTitleMatchMode, 2
CoordMode, Mouse, Window

tt = ahk_exe Game.exe
      WinWait, %tt%
      IfWinNotActive, %tt%,, WinActivate, %tt%

RegionOneLabel:
; very long sequence for region one

RegionTwoLabel:
; very long sequence for region two

RegionThreeLabel:
; very long sequence for region three

Sleep, % 10000
Run taskkill.exe /f /im "Game.exe"
ExitApp
}

F5::
   Goto, RegionOneLabel
return

F6::
   Goto, RegionTwoLabel
return

F7::
   Goto, RegionThreeLabel
return
reddit.com
u/kakashisensei2000 — 5 days ago

[QoL] I "made" this autohotkey script to add extra functions to my mouse and keyboard that I thought might be useful to someone else.

Disclaimer: I did not do this on my own, it is all IA coded, therefore I take no ownership of it - use it however you like.

This script adds a whole lot of functions to the forlorn capslock key. It still works mostly as usual when tapped, but the magic happens once you hold it.

When capslock is held:

Scroll wheel works as media keys, scrolling controls the volume and pressing mutes it.

Spacebar is Play/Pause

The F keys (F1-F12) becomes F13-F24 (yes, they exist)

Tapping the Capslock works as normal with the caveat that it auto toggle it back off after 3s.

; AutoHotkey v2.0 script
global capslockPressedTime := 0

CapsLock:: {
    capslockPressedTime := A_TickCount
    KeyWait("CapsLock") ; wait until released

    holdDuration := A_TickCount - capslockPressedTime

    if (holdDuration &lt; 75) {
        ; Quick tap → toggle CapsLock
        if GetKeyState("CapsLock", "T") {
            SetCapsLockState("Off")
        } else {
            SetCapsLockState("On")
            ; Start auto-off timer
            SetTimer(TurnOffCapsLock, -3000)
        }
    } else {
        ; Held longer than 75ms → suppress CapsLock
        ; Do nothing here, but allow modifier combos below
    }
}

TurnOffCapsLock() {
    if GetKeyState("CapsLock", "T") {
        SetCapsLockState("Off")
    }
}

; Example: Use CapsLock + MouseWheel to control volume with OSD
CapsLock &amp; WheelUp::Send("{Volume_Up}")
CapsLock &amp; WheelDown::Send("{Volume_Down}")
CapsLock &amp; MButton::Send("{Volume_Mute}")
CapsLock &amp; Space::Send("{Media_Play_Pause}")
CapsLock &amp; WheelLeft::Send("{Media_Prev}")
CapsLock &amp; WheelRight::Send("{Media_Next}")
CapsLock &amp; F1::Send("{F13}")
CapsLock &amp; F2::Send("{F14}")
CapsLock &amp; F3::Send("{F15}")
CapsLock &amp; F4::Send("{F16}")
CapsLock &amp; F5::Send("{F17}")
CapsLock &amp; F6::Send("{F18}")
CapsLock &amp; F7::Send("{F19}")
CapsLock &amp; F8::Send("{F20}")
CapsLock &amp; F9::Send("{F21}")
CapsLock &amp; F10::Send("{F22}")
CapsLock &amp; F11::Send("{F23}")
CapsLock &amp; F12::Send("{F24}")
reddit.com
u/AgnFr — 7 days ago

ahk and copilot

The strangest behavior that has already cost me hours and bundles of hair pulled out:
Boiled down to

#!x::                                                           {
        Send("{SHIFT DOWN}")
        Send("{RIGHT 8}")
        Send("{SHIFT UP}")
        Send("^x")
}

it does what it's supposed to but also start copilot????

Any idea what that could be?

Cheers, Merlin

reddit.com
u/ms-bbnj-us — 9 days ago

Favorite uses for AutoHotkey?

Anything you thought was particularly clever? Or made things easier for you significantly?

I've only used AutoHotkey a bit and I am wondering about its use cases.

reddit.com
u/Glum-Pack-3441 — 14 days ago

[Library] Toastify — GDI+ Toast Notifications for AHKv2 (16 themes, 30+ easings, action buttons)

[Library] Toastify — GDI+ Toast Notifications for AHKv2 | 16 themes, 30+ easings, action buttons

Free & MIT licensed. Zero external dependencies beyond the bundled GDI+ wrapper.

GitHub: https://github.com/skeletorflet/AHKv2-Toastification

Quick start

#Include lib\Toastify.ahk
Toastify.Start("dark", Toastify.ALIGN.BOTTOM_RIGHT)
Toastify.Success("Saved!", "Your changes are safe.")

Features

  • 16 built-in themes — DARK, NEON, CYBERPUNK, GLASS, VAPOR, FOREST, PASTEL... (each with a _LIGHT variant)
  • 30+ easing curves — BOUNCE_OUT, ELASTIC_OUT, DECELERATE, and more
  • Compound animations — mix up to 4 styles: SLIDE + FADE + ZOOM + ROTATE
  • Action buttons with callbacks
  • Progress bar that pauses on hover
  • Per-toast or global config
  • DPI-aware, Windows Vista+

Example with action buttons

Toastify.Show("Update Available", "v2.1.0 is ready.", [
    {text: "Update", onClick: (*) =&gt; Run("updater.exe")},
    {text: "Later",  onClick: (*) =&gt; MsgBox("Snoozed")},
], {
    animStyle:  [Toastify.ANIM_STYLE.ZOOM, Toastify.ANIM_STYLE.SLIDE],
    animEasing: Toastify.EASING.BOUNCE_OUT,
    theme:      "cyberpunk",
    duration:   5000,
    showProgress: true,
})

It's a work in progress — looking for feedback, bug reports, and contributors. Any PRs or suggestions are very welcome!

u/Rude_Step — 9 days ago

League of Legends chat issue

I wanted to make the most simple script for typing in chat frequent calls like "bait bot","rush drake",etc. But it seems like the game itselfs dont accept the "virtual" input method from ahk, i tried different keys and it only works for remaps like Numpad2::Esc or smth like that but a simple script for text (i tried and it works everywhere else) doesnt. Something strange is that the first attemps it worked like the first 4-5 times i tried using it in chat, but suddenly stopped working for any script that uses Send or similar text inputs (i even asked chatgpt and it didnt help).
Also tried everythin like opening the chat with enter and then the script just types but nothing.

Is there any solution or is something that vanguard/lol blocks completely?

reddit.com
u/hellolittlecat — 11 days ago

Having an issue with a small script

~WheelDown:: {
	If HWND := WinActive("ahk_group Browser") {
		If InStr(WinGetTitle(HWND), "Youtube")
			Return
	}
}

Basically I want to disable the scroll down button on YouTube pages. I thought the Return would work. Nope. As a test, I replaced it with MsgBox HWND and that did work. As a workaround I am using this,

#HotIf WinActive("ahk_group Browser")
WheelDown::Return
#HotIf

Unfortunately that disables the scroll down button in the entire browser. I prefer my first script.

What is wrong with the first script?

reddit.com
u/Stu_Padasso — 12 days ago

Delay, sleep, or some limiting factor on SendInput

Hi all,

I have carpal tunnel and can't repeatedly click my mouse which is unfortunately somewhat required for playing minecraft. I have a script so that I can use my scroll wheel instead, but I don't want to be able to click 60+ times per second because a) that's super unfair and b) it will trigger an automatic ban from many servers. I know that you cannot implement a key delay for SendInput, but I have tried all the other sending methods and it does not function properly, just lagging my screen and making a bunch of beeping sounds? (I think the same sound as when you have sticky keys on?). Here is my code below; let me know if you can think of any suggestions for this.

#MaxHotkeysPerInterval 100
#If WinActive("Minecraft") &amp;&amp; (WinActive("ahk_exe javaw.exe") || WinActive("ahk_exe java.exe"))

#If GetKeyState("RButton","P")
*WheelDown::SendInput {Click Right}
*WheelUp::SendInput {Click Right}

#If
~RButton Up::Send % InStr(A_PriorHotkey,"Wheel")?"{Return}":


#If GetKeyState("LButton","P")
*WheelDown::SendInput {Click Left}
*WheelUp::SendInput {Click Left}

#If
~LButton Up::Send % InStr(A_PriorHotkey,"Wheel")?"{Return}":
reddit.com
u/sl1dr_ — 13 days ago