send input at program starts

Ask gaming related questions (AHK v1.1 and older)
Oxidia
Posts: 10
Joined: 07 Mar 2022, 21:24

Re: send input at program starts

Post by Oxidia » 08 Mar 2022, 10:31

Hello, thanks very much for you help. Very appreciated.
Sadly it's not working.

This is what i did yesterday but nothing working.

Code: Select all

#Persistent

#SingleInstance, force

#IfWinActive, "G:\Higan\higan.exe"

WinWait,, Seek

Sleep, 1000

ControlSend, , {R}, ahk_exe higan.exe
[Mod edit: [code][/code] tags added.]
Last edited by BoBo on 08 Mar 2022, 11:47, edited 1 time in total.
Reason: Moved to Gaming section.

sofista
Posts: 650
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: send input at program starts

Post by sofista » 08 Mar 2022, 11:07

Oxidia wrote:
08 Mar 2022, 10:23
Send, {R}
Try to send R without braces, they are not needed here.

Hardcoder
Posts: 278
Joined: 19 Feb 2022, 13:13
Location: Germany

Re: send input at program starts

Post by Hardcoder » 08 Mar 2022, 11:20

I don't know your program, but you can at first try to clean up
- send R without braces, as Oxidia said
- If this is all of your code, the #IfWinActive does nothing, this is only for hotkeys and hotstrings
- Why do you use WinWait but then Sleep for a second?
- WinWait will only wait until a Window exists, not until it is active.

Lastly, you did not specify what you are trying to do.

I can only guess, you want something like this:

Code: Select all

#Persistent
#SingleInstance Force

If ( WinExist("ahk_exe higan.exe") )
{
	WinActivate
	Send, R
}

Oxidia
Posts: 10
Joined: 07 Mar 2022, 21:24

Re: send input at program starts

Post by Oxidia » 08 Mar 2022, 11:35

Thanks guys, like i said on my previous post.
When i launch a game on Higan ( it's an emulator) i have to press a key everytime to enter in fullscreen mode. I don't know why but Higan have no option implanted to do that.
This is my goal.
Thanks again i'm very grateful that you help me, i'm still trying all of your script but at this time nothing work.
I've seen on the web that it need a sleep time or it will won't work., this is why i'm trying.
Last edited by Oxidia on 08 Mar 2022, 11:52, edited 1 time in total.

Hardcoder
Posts: 278
Joined: 19 Feb 2022, 13:13
Location: Germany

Re: send input at program starts

Post by Hardcoder » 08 Mar 2022, 11:51

Oxidia wrote:
08 Mar 2022, 11:35
Thanks guys, like i said on my previous post.
When i launch a game on Higan ( it's an emulator) i have to press a key everytime to enter in fullscreen mode. I don't know why but Higan have no option implanted to to that.
This is my goal.
Thanks again i'm very grateful that help me, i'm still trying all of your script but at this time nothing work.
I've seen on the web that it need a sleep time or it will won't work., this is why i'm trying.
Oh sorry, I did not read the first post again, my bad.
But in theory this should be enough
- start the program
- wait for it to load
- send keystroke
If your emulator goes into full screen with pressing R, my last posted code should do that.
Unless the R should be sent to a sub control of the window.
You could also try WinMaximize, maybe that does the trick.

https://www.autohotkey.com/docs/commands/WinMaximize.htm

RussF
Posts: 1269
Joined: 05 Aug 2021, 06:36

Re: send input at program starts

Post by RussF » 08 Mar 2022, 11:55

From the Higan documentation:
Fullscreen Mode settings apply when higan is running fullscreen, because it was started with the --fullscreen command-line option or because the user pressed the Toggle Fullscreen hotkey.
Perhaps you can edit the shortcut that launches Higan and add --fullscreen to the end of the command line.

Russ

Oxidia
Posts: 10
Joined: 07 Mar 2022, 21:24

Re: send input at program starts

Post by Oxidia » 08 Mar 2022, 12:04

No problem Hardcoder you don't have to say sorry, You're trying to help and it's awesome.
Thanks RussF i'm about to explore this way too.
You guys are the best

Hardcoder
Posts: 278
Joined: 19 Feb 2022, 13:13
Location: Germany

Re: send input at program starts

Post by Hardcoder » 08 Mar 2022, 12:28

I downloaded that emulator, though it is called bsnes.exe but it should be the same.
And I cannot get it to work either, tried it with r and with the default F11, nothing :/
--fullscreen start parameter seems to do nothing additional.
Of course, just pressing the key works :cry:
But i'm not yet giving up

Code: Select all

#SingleInstance Force
#Persistent
#NoEnv

WinKill, ahk_exe bsnes.exe
Run, C:\Users\xxx\Downloads\bsnes_v115-windows\bsnes.exe

WinWaitActive, ahk_exe bsnes.exe
Return

^e::
	SoundBeep, 1000
	Send, {F11}
	Sleep, 500
	SoundBeep, 1000
	SendInput, {F11}
	Sleep, 500
	SoundBeep, 1000
	SendPlay, {F11}
	Sleep, 500
	SoundBeep, 1000
	SendEvent, {F11}
	
	Loop, 7
	{
		Sleep, 500
		freq := 1000 + A_Index * 200
		SoundBeep, %freq%
		ControlSend, hiroWidget%n%, {F11}, ahk_exe bsnes.exe
	}
Return

Oxidia
Posts: 10
Joined: 07 Mar 2022, 21:24

Re: send input at program starts

Post by Oxidia » 08 Mar 2022, 12:47

Wow thanks for your investment ! Yes Bsnes was an old version
I found it and it works every time without closing autohotkey, I'm so happy !!!
I added one more thing on the script :
" long press esc to force close Higan" but it doesn't work until i press R again to back on borderless mode. Alt + F4 dosen't work in fulscreen mode too. This emulator is very strange.

Works with Higan v106

Code: Select all

#Persistent
#SingleInstance, force
Loop{
	WinWait, ahk_exe higan.exe
 Sleep, 1000
 SetKeyDelay, -1, 110
 Send R
WinWaitClose, ahk_exe Higan.exe
}

~$Esc::                         ; Long press (> 0.5 sec) on Esc closes window
KeyWait, Escape, T0.5           ; Wait no more than 0.5 sec for key release (also suppress auto-repeat)
If ErrorLevel                   ; timeout, so long press
	PostMessage, 0x112, 0xF060,,, A    ;Use PostMessage to close window
Return
[Mod edit: [code][/code] tags added.]
Last edited by Oxidia on 08 Mar 2022, 13:10, edited 2 times in total.

Oxidia
Posts: 10
Joined: 07 Mar 2022, 21:24

Re: send input at program starts

Post by Oxidia » 08 Mar 2022, 12:54

bad news , it works when i double click on higan.exe but not when i double kick on a game directly.
Exemple of game file :
Super Mario Bros. 3 (USA).nes

Anyway i'm happy for this first step.
I'll be back if i find a way to fix it. Thanks you guys again

Hardcoder
Posts: 278
Joined: 19 Feb 2022, 13:13
Location: Germany

Re: send input at program starts

Post by Hardcoder » 08 Mar 2022, 13:05

I found a solution, you have to send {R Down} twice with a delay, and a short delay before, no clue what this program is doing there.
Though, now I had to press the key twice to get out of fullscreen tho :D

Ok, you have found a solution yourself, maybe this works for your new problem too?

Code: Select all

#SingleInstance Force
#Persistent
#NoEnv

WinKill, ahk_exe bsnes.exe
Run, C:\Users\admin\Downloads\bsnes_v115-windows\bsnes.exe

WinWaitActive, ahk_exe bsnes.exe

Sleep, 500

SoundBeep, 1000

SendInput, {F11 Down}
Sleep, 600
SendInput, {F11 Down}

SoundBeep, 1000
Return

Hardcoder
Posts: 278
Joined: 19 Feb 2022, 13:13
Location: Germany

Re: send input at program starts

Post by Hardcoder » 08 Mar 2022, 13:08

Oh, I see you changed press duration, yes thats probably better.

Edit: That doesn't work with bsnes.exe :facepalm:

Hardcoder
Posts: 278
Joined: 19 Feb 2022, 13:13
Location: Germany

Re: send input at program starts

Post by Hardcoder » 08 Mar 2022, 13:14

Have you looked if the title changes, when you directly load a game?

Oxidia
Posts: 10
Joined: 07 Mar 2022, 21:24

Re: send input at program starts

Post by Oxidia » 08 Mar 2022, 13:24

🤣 i think it is really cool you found it for bsnes, many people are still playing on this one too.
Yes you're totaly right, this is what I also suspected.
In my case window name change to : Super Mario Bros. 3 (USA)
and this is not a good news i think,
which means that I have to group all games in one script.
Don't know if autohotkey support this

Oxidia
Posts: 10
Joined: 07 Mar 2022, 21:24

Re: send input at program starts

Post by Oxidia » 08 Mar 2022, 17:17

Got it working for one game. Last thing is, how to do dupplicate it for all games in only one script ?

Code: Select all

#Persistent
#SingleInstance, force
Loop{

WinWait, Super Mario Bros. 3 (USA) 

Sleep, 1000
SetKeyDelay, -1, 110
Send R

WinWaitClose, Super Mario Bros. 3 (USA)
}
Return
[Mod edit: [code][/code] tags added.]
Last edited by gregster on 08 Mar 2022, 17:31, edited 1 time in total.
Reason: Please use code tags. Thank you!

Oxidia
Posts: 10
Joined: 07 Mar 2022, 21:24

Re: send input at program starts

Post by Oxidia » 08 Mar 2022, 21:08

Finally Done !!!
I used Higan v106
I added "press esc to exit" and now it works perfectly too.
For Higan users like me who will need this script, if you have an issue, maybe you should increase " Sleep" value.

Code: Select all

#Persistent
#SingleInstance, force
Loop{

    WinWait, ahk_exe higan.exe
         

 Sleep, 2000
 SetKeyDelay, -1, 110
 Send R     
WinWaitClose, ahk_exe higan.exe

}
Esc::WinClose, ahk_exe higan.exe
Return

See You and thanks to those who helped me 😀

Hardcoder
Posts: 278
Joined: 19 Feb 2022, 13:13
Location: Germany

Re: send input at program starts

Post by Hardcoder » 09 Mar 2022, 02:41

Nice :thumbup:

Germy
Posts: 1
Joined: 16 May 2022, 09:11

Re: send input at program starts

Post by Germy » 16 May 2022, 09:37

HI Guys. I'm try to accomplish the same as before (alt-enter as soon as the program has been started) , but for some kind of reason it's not working for me -at all- .
This is the code i currently use:
What am i doing wrong? Sorry if it's a stupid mistake, i am an absolute rookie when it comes to autohotkey.

Code: Select all

Run, C:\Program Files\PuTTY\putty.exe -load shelfpick -l XXX -pw XXX
WinWait, ahk_exe C:\Program Files\PuTTY\putty.exe -load shelfpick -l XXX -pw XXX
WinActivate, ahk_exe C:\Program Files\PuTTY\putty.exe -load shelfpick -l XXX -pw XXX
Sleep, 3000
SendInput,!{Enter}
[Mod edit: [code][/code] tags added.]
Your help is highly appreciated !

Post Reply

Return to “Gaming Help (v1)”