Send() to Unity window

Ask gaming related questions
avernikov
Posts: 7
Joined: 19 Jun 2021, 19:46

Send() to Unity window

Post by avernikov » 21 Mar 2024, 14:36

Hello,
I have a simple script sending 2 keystrokes to a Unity window(UnityWndClass).

Code: Select all

Loop
{
	Send "K"
	Sleep(5000)
	Send "T"
	Sleep(3000)
}
These keys are bound to some in-game actions. When I run that script, only the "K" is received by the game, "T" is not received ever. I tried to re-bind(swap) the keys in the game, and well, the another key was received, meaning that it is the in-game action that is somehow rejecting the Send()- generated keystroke...
I have tried
- changing to SendInput - same result
- changing to SendPlay - no keys arrive at all
- add SetKeyDelay - same result
My last try:

Code: Select all

InstallKeybdHook
SetKeyDelay(50,100)
MsgBox("ready?")
SendMode "Input"
Send "K"
Sleep(4000)
Loop
{
	Send "K"
	Sleep(5000)
	Send "T"
	Sleep(1000)
	SendInput "T"
	Sleep(1000)
	SendPlay "T"
	Sleep(1000)
}
No single action mapped to "T" is executed...

Any suggestions? Thanks in advance!

Rohwedder
Posts: 7655
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Send() to Unity window

Post by Rohwedder » 22 Mar 2024, 03:14

Hallo,
perhaps??:

Code: Select all

Loop
{
	Send "k"
	Sleep(5000)
	Send "t"
	Sleep(3000)
}

avernikov
Posts: 7
Joined: 19 Jun 2021, 19:46

Re: Send() to Unity window

Post by avernikov » 23 Mar 2024, 18:00

Rohwedder wrote:
22 Mar 2024, 03:14
Hallo,
perhaps??:

Code: Select all

Loop
{
	Send "k"
	Sleep(5000)
	Send "t"
	Sleep(3000)
}
Unfortunately no, caps/no caps same result, already tried.

niCode
Posts: 295
Joined: 17 Oct 2022, 22:09

Re: Send() to Unity window

Post by niCode » 23 Mar 2024, 21:57

If it's only that action being rejected, I suspect there's no fix. The game was probably coded like that intentionally, because it doesn't really make sense for the game to see only some common keys and not others.

One thing to note though: you said you tried changing to SendInput. Unlike v1, SendInput is actually the default send mode and SetKeyDelay doesn't affect SendInput. Try SendEvent.

Post Reply

Return to “Gaming”