Problem with shortcut excecuting only once

Discussion, questions and support.
Post Reply
mr9bitbyte
Posts: 32
Joined: Apr 25th, ’23, 17:20

Post by mr9bitbyte » Apr 27th, ’23, 00:23

I have this code I want to run with a Command in the shortcut section:, the shortcut to run this is Ctrl+f, for some reason it runs once, then it doesnt after that. if I put this script inside ahk file, and do a run command, everything works prefect. What is the problem?

Code below:

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.


#Persistent
#SingleInstance, Force
; Add a short delay before sending Ctrl+F at the beginning
Send, ^f

; Loop to check for the ENTER key press
startTime := A_TickCount
while (A_TickCount - startTime) <= 10000 {
if GetKeyState("Enter", "P") {
Sleep, 200 ; Add a short delay to ensure the ENTER key press is processed
Send, ^f
Sleep, 50 ; Wait 50 milliseconds (optional, adjust as needed)
Send, {Esc}
ExitApp
}
Sleep, 50 ; Sleep to avoid high CPU usage
}

; If no key is pressed within 10 seconds, exit the script
ExitApp
User avatar
Marko
Posts: 1771
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Apr 30th, ’23, 14:31

Avoid ExitApp command in FastKeys scripts, replace it with Return.
User avatar
Oblomov
Posts: 186
Joined: Mar 4th, ’19, 19:44

Post by Oblomov » Jul 20th, ’23, 19:47

Marko wrote: Apr 30th, ’23, 14:31 Avoid ExitApp command in FastKeys scripts, replace it with Return.
But it seems something like 'e::return' is even worse than 'e::exitapp' though...
Post Reply