send input at program starts

Ask gaming related questions (AHK v1.1 and older)
shady8knight
Posts: 9
Joined: 12 Apr 2018, 11:30

send input at program starts

12 Apr 2018, 11:41

Hello everyone, I'm not an expert, I'm learning and I have serached as best as I can to find a solution but nothing seems to work properly. My problem is that I have to automatize the pressure of alt+enter when a program starts and opens his window. I need this to set the window in fullscreen and the only way to do that is by pressing alt+enter when this program (demul.exe) starts. Tried a lot of combinations but noyhing..... any solution please? Thanks
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: send input at program starts

12 Apr 2018, 13:36

Can you post the script you have so far?
User avatar
BriHecato
Posts: 124
Joined: 18 Jul 2017, 07:17

Re: send input at program starts

12 Apr 2018, 23:54

I would write script that run this exe (if possible) then wait for it to finish launching, then send your keys, then close script. ALl this behave like lnk windows shortcut but would be ahk script :)
Have you tried WinMove to resize app window?
shady8knight
Posts: 9
Joined: 12 Apr 2018, 11:30

Re: send input at program starts

13 Apr 2018, 03:06

Thanks for the answers, this is the last script i tried:

if Process, Exist, demul.exe
If ErrorLevel <> 0
SendInput, !enter

I have tried even with winactive but nothing. When i launch the programm demul.exe it stand windowed.
shady8knight
Posts: 9
Joined: 12 Apr 2018, 11:30

Re: send input at program starts

13 Apr 2018, 03:08

BriHecato wrote:I would write script that run this exe (if possible) then wait for it to finish launching, then send your keys, then close script. ALl this behave like lnk windows shortcut but would be ahk script :)
Have you tried WinMove to resize app window?
Yes but it doesn't solve the problem. The program need alt+enter to go completely fullscreen and hide the gui and the mouse cursor too
User avatar
BriHecato
Posts: 124
Joined: 18 Jul 2017, 07:17

Re: send input at program starts

13 Apr 2018, 09:17

Why If proces exist?
Why sendinput?


That wouldn't work?

Code: Select all

RunWait, your_path\demul.exe
IfWinActive, ahk_exe demul.exe	;;;just to be sure
Send, {Alt}{Enter}
ExitApp
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
Location: Middle of the round cube
Contact:

Re: send input at program starts

13 Apr 2018, 09:53

BriHecato wrote:That wouldn't work?

Code: Select all

RunWait, your_path\demul.exe
IfWinActive, ahk_exe demul.exe	;;;just to be sure
Send, {Alt}{Enter}
ExitApp
This won't work, because RunWait waits for the exe to run and stop. I don't believe you tested this code.

Here's a general idea to get you started.

Code: Select all

; run the exe
Run, demul.exe ; you'll have to specify the path
; Wait for the window to appear
WinWait, ahk_exe demul.exe
; Activate the window
WinActivate, ahk_exe demul.exe
; Send Alt+Enter
; if this happens to soon, i.e. the program doesn't accept this keypress because it's still starting, you could specify a sleep long enough to allow the program to finish loading
; Sleep, (a little longer than required to ensure consistent behaviour)
SendInput, !{Enter} ; Use SendInput just in case SendMode isn't input
:wave:
try it and see
...
User avatar
BriHecato
Posts: 124
Joined: 18 Jul 2017, 07:17

Re: send input at program starts

13 Apr 2018, 10:13

derz00 wrote: This won't work, because RunWait waits for the exe to run and stop. I don't believe you tested this code.
I'm not familiar with this emulator shadyknight is using, if it use splashscreen, or is titlebarless or busy loading subcomponents after launch (like apps that they little more time after the exe is loaded and displayed and do not response to any actions yet).
That's why I asked why he use SendInput in this situation, why is he checking for process with less popular If, Exist, Process.

Let's wait what shady has to say.
Maybe he need to recheck exe, class, controls, whole behaviour of this software, maybe need put some if/else, some forced sleep. Maybe he forget about {} for enter :)

I use everyday code with Run - WinWait - WinMove to place and resize some stubborn app. But Run+WinWait = RunWait, true?
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
Location: Middle of the round cube
Contact:

Re: send input at program starts

13 Apr 2018, 10:26

BriHecato wrote:AFAIK RunWait waits for finish loading then continue the script
You might know further (referring to the AFAIK modifier) by reading the documentation. According to https://autohotkey.com/docs/commands/Run.htm RunWait wait until the program exits not finishes loading.

Another part about your code that wouldn't have worked is {Alt}{Enter}. That will not send the keyboard combination Alt+Enter. It will be the same as pressing and releasing {Alt} and then pressing and releasing {Enter}.

Not big issues, but just remember to test any code before posting (or at least say it has not been tested) to make sure that the code is right and the result is right.

3 Cheers for all your helpfulness in this forum. :thumbup: :thumbup: :thumbup:
try it and see
...
shady8knight
Posts: 9
Joined: 12 Apr 2018, 11:30

Re: send input at program starts

14 Apr 2018, 13:24

Thank you guys, I appreciate so much your help. This one works fine but with only one problem....

Run, C:\demul07_111117\demul.exe
WinWait, ahk_exe demul.exe
WinActivate, ahk_exe demul.exe
SendInput, !{Enter}

If i launch the ahk script demul starts by itself. I would the script simulate the pressure of alt+enter when I open demul (i do it launching directly roms from frontend program).
What do i have to change in this script? Thank you very much
shady8knight
Posts: 9
Joined: 12 Apr 2018, 11:30

Re: send input at program starts

15 Apr 2018, 17:50

Tried to change the script but nothing works better than that, i should just not launch demul.exe with the run of the script. And another little problem that i noticed trying lot of times the script, somethimes, not always the script simulate the pressure of alt+enter before of window launch so that appear the demul.exe properties window instead of send the demul window in fullscreen so i think i have to set a wait time before the sendinput line just as derz00 suggested but don't know how to do.

That's all because i'm building an arcade cabinet with all the emulators inside and i have this problem with demul. with the frontend program i shuold choice the rom and it automatically launch the emulator. all of them works fine but demul doesn't go fullscreen, that's why i need to do it with this script. thank you for help.
User avatar
BriHecato
Posts: 124
Joined: 18 Jul 2017, 07:17

Re: send input at program starts

16 Apr 2018, 01:38

@Shady - just put some
Sleep, xxx
between winwait and winactivate (and if necessary) between winactivate and sendinput.
Check behavior of the app and tune those sleeps.
Try also winactivate precise ahk_class (check with winspy) not emulator exe.

@derz00 - sorry for my rush language towards you. My observations were just mine from perspective of my code that (maybe wrong, and with wrong fundamentals) works in the end. Not mean to offend anyone.
shady8knight
Posts: 9
Joined: 12 Apr 2018, 11:30

Re: send input at program starts

16 Apr 2018, 03:22

Ok, thank you bri, thanks to all your suggestion and some attempts i'm almost on goal, this is the script i'm running now:

WinWait, ahk_exe demul.exe
WinActivate, ahk_exe demul.exe
Sleep, 3000
SendInput, !{Enter}

it works fine but just with one problem (i hope this is the last one).... it works fine just the firs time demul.exe is launched. if i close it and launch again it doesn't work anymore. if i close the script, run the script again and launch demul.exe it works again but always just for the first time.

i've tried yet with

loop {
....
}

and easily with

{
....
}

but nothing, the first press repetetly alt+enter and goes fullscrre/windowed/fullscreen/windowed, the second doesn't change anything. thank you
User avatar
BriHecato
Posts: 124
Joined: 18 Jul 2017, 07:17

Re: send input at program starts

16 Apr 2018, 06:04

Use this script as your "*.lnk" to launch this app everytime - do not click app shortcunt on desktop - but click your "script launcher-shortcut"
(add ExitApp on the end of script to self-close it after succesfull launch)

You wrote -
"i should just not launch demul.exe with the run of the script"
- why ?? Any problems with it ?

Otherwise you need to create settimer that check in some intervals if your emulator window (or exe or class) exist and isn't full screen - then make it full screen.
shady8knight
Posts: 9
Joined: 12 Apr 2018, 11:30

Re: send input at program starts

16 Apr 2018, 06:49

Thank you again. I have a script that have to be always working because it has some command that i need to use with the frontedn program. i have to run the script at windows start and never close it. now i have edited it like this....

WinWait, ahk_exe demul.exe
WinActivate, ahk_exe demul.exe
Sleep, 3000
SendInput, !{Enter}
ExitApp

(after that i have severl command that are working fine.....)

so the script closes itself when demul got fullscreen, i need that it stays always running and do his function of pressing alt+enter everytime demul is runned by the frontend. selecting different roms the frontend open demul, close demul, open demul and close it again lot of times, once for every rom i want to play. that's why i do not launch demul but the frontend does it when i select a rom for demul. i'm sorry if i don't explain myself so good, english is not even my language, i'm from italy.
shady8knight
Posts: 9
Joined: 12 Apr 2018, 11:30

Re: send input at program starts

18 Apr 2018, 08:55

I'm crushing the head on the floor, I can't find a solution, the better script is

WinWait, ahk_exe demul.exe
WinActivate, ahk_exe demul.exe
Sleep, 3000
SendInput, !{Enter}

but it works just for the first time, if i esc demul and open it again doesn't work anymore. Please help......... thank you.
shady8knight
Posts: 9
Joined: 12 Apr 2018, 11:30

Re: send input at program starts

20 Apr 2018, 02:49

Thank you guys, problem solved with a frontend trick using the script above. Thank you for help.
Oxidia
Posts: 10
Joined: 07 Mar 2022, 21:24

Re: send input at program starts

07 Mar 2022, 21:28

Hello,
Did you finally find a way to do this perfectly without frontend ?
I'm searching exactly the same thing with Higan.exe emulator. I need to press a key every time higan start to enter in fullscreen mode.
Hardcoder
Posts: 278
Joined: 19 Feb 2022, 13:13
Location: Germany

Re: send input at program starts

08 Mar 2022, 04:19

How about putting a loop around that?

Code: Select all

Loop
{
	WinWaitActive, ahk_exe Higan.exe
	Sleep, 1000 ; if you have to
	Send, whatever_you_need
	WinWaitClose, ahk_exe Higan.exe
}
Oxidia
Posts: 10
Joined: 07 Mar 2022, 21:24

Re: send input at program starts

08 Mar 2022, 10:23

Hello, thanks very much for your help, very appreciated.
Sadly nothing happen

This is what i was doing :

#Persistent
#If WinActive, "G:\Higan\higan.exe"
If WinExist, "G:\Higan\higan.exe"

WinWait,, Seek

Sleep, 1000

Send, {R}

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 92 guests