controlsend not working in game

Get help with using AutoHotkey and its commands and hotkeys
densch
Posts: 46
Joined: 29 May 2018, 15:10

controlsend not working in game

23 Jun 2019, 01:02

Hey, I am playing some old game on this super nintendo emulator
(ZSNES on this list is the used emulator: https://romsmania.cc/emulators/super-nintendo)

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?
densch
Posts: 46
Joined: 29 May 2018, 15:10

Re: controlsend not working in game

23 Jun 2019, 04:56

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 :-(
swagfag
Posts: 3063
Joined: 11 Jan 2017, 17:59

Re: controlsend not working in game

23 Jun 2019, 08:34

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

#NoEnv
SetBatchLines -1
SetTitleMatchMode 2

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

logFile := "zsnes.log"
log := FileOpen(logFile, "w")
OnExit("openLogFile")
openLogFile() {
	global
	log.Close()
	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)
					}
					else
						test(ctrl, title, mode, delay, duration)
				}
			}
		}
	}
}

ExitApp
Esc::ExitApp

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

	global testsTotal, key, log

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

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

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

	log.Write(test)
}
densch
Posts: 46
Joined: 29 May 2018, 15:10

Re: controlsend not working in game

23 Jun 2019, 12:58

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?
swagfag
Posts: 3063
Joined: 11 Jan 2017, 17:59

Re: controlsend not working in game

23 Jun 2019, 13:30

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.
densch
Posts: 46
Joined: 29 May 2018, 15:10

Re: controlsend not working in game

24 Jun 2019, 13:18

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 :-(
densch
Posts: 46
Joined: 29 May 2018, 15:10

Re: controlsend not working in game

24 Jun 2019, 13:23

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 :-/
densch
Posts: 46
Joined: 29 May 2018, 15:10

Re: controlsend not working in game

24 Jun 2019, 14:04

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:
PID!
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! :-)
swagfag
Posts: 3063
Joined: 11 Jan 2017, 17:59

Re: controlsend not working in game

24 Jun 2019, 14:12

Looping a key may emulate holding it down, however, its not quite the same as actually holding it down

Return to “Ask For Help”

Who is online

Users browsing this forum: cainxabel, Google [Bot] and 204 guests