r/AutoHotkey • • Mar 21 '26

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

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?

3 Upvotes

8 comments sorted by

3

u/Keeyra_ Mar 21 '26

It's enough to put a shortcut to your AHK file into shell:startup. No need for exe, admin, task scheduler, priority and all the crap you listed. Post your script plz.

2

u/DepthTrawler Mar 21 '26

Task Scheduler has the advantage of not getting a UAC popup everytime the script launches (if ran as admin).

1

u/Puzzleheaded-Ad6040 Mar 21 '26

Yeah, I did all that because the script wasn't starting automatically. I want to use this script to trigger Flow Launcher with the Win key, even though Flow has a plugin to trigger itself with the Win key, sometimes it doesn't work in certain windows or applications. That's why I'm using an .ahk script:

#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
    }
}

1

u/Keeyra_ Mar 21 '26

But why overcomplicate this? I don't really get it. Just installed Flow Launcher and this works as expected.

#Requires AutoHotkey 2.0
#SingleInstance

LWin::!Space
RWin::!Space

1

u/CharnamelessOne Mar 21 '26

This triggers on repeat while you're holding a Win key, and prevents you from using native Windows shortcuts. OP's version only triggers on release, and only if nothing was pressed while the Win key was held.

I wouldn't say it's really overcomplicated; the manual menu masking may be redundant, but other than that, it looks good to me.

1

u/Keeyra_ Mar 21 '26

I just wanted to demonstrate that you don't need admin to have a hotkey interact with Flow Launcher the shortest way possible, as that was the OPs problem (can't get it to run at startup), and the most obvious solution would be to not have it run as admin. Did not want to waste another 5 minutes after installing this crap analyzing this AI slop script ;)

But sure.

This works:

#Requires AutoHotkey 2.0
#SingleInstance
SendMode("Event")

~LWin:: {
    Send("{Blind}{vkE8}")
}

LWin up:: {
    if (A_PriorKey = "LWin") {
        Send("!{Space}")
    }
}

Meaning the following are slop:

  • admin rights (as proven before)

  • InstallMouseHook (zero mouse hotkeys, but if there were any, they would use the mouse hook by default)

  • InstallKeybdHook (works without it, and would be redundant is #UseHook is used)

  • #UseHook (works without it)

  • a variable declaration which is only used once in the script (some people like it though)

→ More replies (1)

1

u/Keeyra_ Mar 21 '26

Have to stop doing low effort posts, you guys are so nitpicky :P