0
votes

I am pretty new to AutoHotkey, but I managed it to start my desired program and send an Enter-Key to it, but the probleme here is, the program should only start once and if started it should only receive that enter key, when I press the key stroke again and again it should only send that enter key.

And the program should should stay in the background and not focus after it receives the enter key.

My Code:

#n::
Run F:\V..c.exe
Send {enter}
return
2
you mean you want to run the program V..c.exe only once ?AmirHossein
yes, and if the program is up, it should only receive the enterkey int the backgrounduser254197

2 Answers

1
votes

Detect if the process exists and start the program minimized, then wait for its window to appear.

#n::
  process, exist, PROGRAM.EXE
  if (errorlevel = 0) {
    run, d:\program.exe, , min
    winwait, ahk_class PROGRAM_WINDOW_CLASS
  }
  controlSend, , {Enter}, ahk_class PROGRAM_WINDOW_CLASS
  ;or use the line below
  ;controlSend, ahk_parent, {Enter}, ahk_class PROGRAM_WINDOW_CLASS
  return

Replace PROGRAM.EXE with the executable name of your program and PROGRAM_WINDOW_CLASS with the window class as seen in the Autohotkey Window Spy utility available in Start menu or in the folder of the Autohotkey (AU3_Spy.exe) or in the right click menu of the Autohotkey tray icon.


Instead of running the program minimized it's also possible to use SW_SHOWNOACTIVATE flag of shellExecute, so you can replace the run, d:\program,, min with this:

dllCall("shell32\ShellExecute", uint,0, uint,0, str,"d:\program.exe", uint,0, uint,0
        ,uint,SW_SHOWNOACTIVATE:=4)
0
votes

you could try:

hasran := false
#n::
if (!hasran) {
    Run F:\V..c.exe
    hasran := true
}
Send {enter}
return

It wont check if that windows exists, but it will only run the program once. then you can navigate to that program and it will only hit the enter key. (if that program is not gui I dont think you can send key events to it)