Page 1 of 1

controlsend not working in game

Posted: 23 Jun 2019, 01:02
by densch
Hey, I am playing some old game on this super nintendo emulator
(ZSNES on this list is the used emulator:

now i have a script with Send commands and co that works great. but I wanted to use controlsend so I dont have to have the game window open at all times.

but unfortunately no matter what I do , I just cant get controlsend to work. at all!
it never does the button press ({Up down} to be precisely).
I know that the window has no controls, ahk_class ZSNES and ahk_exe zsnesw.exe

but no matter in what variation I try to use controlsend, it jsut never works.
ommiting the second command or putting ahk_parent there does nothing.

yet again, all "send" commands work perfectly, so the window sure is responsive.
had it run for hours without problems.

but it just doesnt react to controlsend input :-/

does anyone have a good idea what the issue might be?

Or is there some sort of alternative to the controlsend command?

Re: controlsend not working in game

Posted: 23 Jun 2019, 04:56
by densch
Okay, I just tried using controlsend with notepad, which is recommended around here a lot.
not even that seems to work :-(

I must be doing something fundamentally wrong and don't know what :-(

Re: controlsend not working in game

Posted: 23 Jun 2019, 08:34
by swagfag
i think ControlSend has 0% chance of working but u could try the following regardless. run the game, set it up so theres some observable behavior that u can observe when a key is pressed(eg space => jump, but urs might be different so ud have to change that), run the script, sit through 500 tests and observe if anything happens on screen when a test is run.

Code: Select all

SetBatchLines -1
SetTitleMatchMode 2

key := "{Space}"
exe := "ahk_exe zsnesw.exe"
hwnd := WinExist(exe)
if !hwnd
	MsgBox Hwnd not found. Exiting.

logFile := "zsnes.log"
log := FileOpen(logFile, "w")
openLogFile() {
	Run % logFile

Controls := ["", "ahk_parent"]
WinTitles := ["ZSNES", "ahk_class ZSNES", exe, "ahk_id " hwnd]
SendModes := ["Event", "Play", "Input"]
KeyDelays := [-1, 0, 100]
PressDurations := KeyDelays
PlayParams := ["", "Play"]

testsTotal := 1
for each, Setting in [Controls, WinTitles, SendModes, KeyDelays, PressDurations, PlayParams]
	testsTotal *= Setting.Count()

for each, ctrl in Controls
	for each, title in WinTitles
		for each, mode in SendModes
			for each, delay in KeyDelays
				for each, duration in PressDurations
					if (mode ~= "Event|Play")
						for each, playParam in PlayParams
							test(ctrl, title, mode, delay, duration, playParam)
						test(ctrl, title, mode, delay, duration)


test(ctrl, title, mode, delay, duration, playParam := "") {
	static i := 0

	global testsTotal, key, log

	SendMode % mode
	SetKeyDelay % delay, % duration, % playParam

	MsgBox % test := Format("
		Test #{} of {}
		SendMode {}
		SetKeyDelay {}, {}{}
		ControlSend, {}, {}, {}

	)", ++i, testsTotal, mode, delay, duration
	, playParam ? ", " playParam : "", ctrl, key, title)
	Loop 10
		ControlSend % ctrl, % key, % title


Re: controlsend not working in game

Posted: 23 Jun 2019, 12:58
by densch
Did the test, literal nothing happened in all these cases.
as mentioned before, for whatever reason
not even
controlsent, Edit1, {x}, Untitled
does anything when notepad is open.

What am I doing so wrong? :-/

is there some alternative to controlsend?

Re: controlsend not working in game

Posted: 23 Jun 2019, 13:30
by swagfag
well if u have controlsent, Edit1, {x}, Untitled written in ur script, then this is what ure doing wrong
otherwise, make sure u run the script as admin and make sure there's no winTitle mismatch, ie ure targetting the right window and doing it correctly(in accordance to the current TitleMatchMode)
if it doesnt work, check ur script for semantic errors, typos and such
if it still doesnt work, then it wont work ever.

Re: controlsend not working in game

Posted: 24 Jun 2019, 13:18
by densch
that one was just a typo here in the forum.
i tried everything but it just wont work :-/

is there some alternative to controlsend?
i cant even get it to write in normal notepad :-(

Re: controlsend not working in game

Posted: 24 Jun 2019, 13:23
by densch
nevermind, i just created a completely new empty script, put in hte example from the controlsend page.
after modifying the title (it just doesnt say Untitled.) it worked.

so controlsend is working.
it just doesnt work with my game for whatever reason :-(

from what I heard, controlsend doesnt seem to like pressed down keys either :-/

Re: controlsend not working in game

Posted: 24 Jun 2019, 14:04
by densch
oh my god, I finally made it work! (At least partially)
the whole time I did what was written everywhere.
use the windows title, it's ahk_class or it's ahk_exe.

but when reading on what wintitle could be, i found something foolproof:
the corresponding process' id!

sure, I would probably have to look it up each time I start the game.

but well, I wouldnt do this stuff too often anyways.
start the game, let it grind for hours, finished.
a one time thing.

but it just seems that holding down buttons really isn't possible with controlsend :-/

but aside from that normal button presses can be done! :-)

Re: controlsend not working in game

Posted: 24 Jun 2019, 14:12
by swagfag
Looping a key may emulate holding it down, however, its not quite the same as actually holding it down