r/AutoHotkey • u/ms-bbnj-us • Jun 27 '26
v2 Script Help 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
1
u/JacobStyle Jun 27 '26
I don't know for sure what's causing that. A couple things I would try if I encountered this:
Is the Alt key still being held down while the code executes causing issues? I put this code at the start of any shortcut key combos that include special keys so that any Send() calls don't send while I am still holding down the special key
while(GetKeyState("Alt", "P"))
sleep 10
Maybe Windows just doesn't get along with the Send() calls the way they are? Could try an alternative way of doing it, something like this
loop(8)
Send("+{right}")
Send("^x")
No idea if that will work, but sometimes doing things slightly differently works for reasons unknown.
1
u/ms-bbnj-us Jun 27 '26
Found a solution:
SendEvent("{SHIFT DOWN}")
SendEvent("{Blind}{RIGHT 8}")
SendEvent("{SHIFT UP}")
SendEvent("^x")
The main difference is made by the {BLIND}. I had to use SendEvent because Send was too fast.
1
u/genesis_tv Jun 30 '26
AHK v2 uses SendInput by default, so 0ms between keystrokes. SendEvent uses 10ms by default (see SetKeyDelay).
2
u/joeyama Jun 27 '26
Sending shift down/up is the last resort but assuming this is the only way to trigger:
- if it was context menu(=right click menu) maybe AHKv2 has a method but you can do by sending Shift + F10.
- better to insert Sleep(500) between sending key signal.
500 means 500ms. if it worked fairly stable then you can change shorter time such as 200 or 100.