Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

Ask gaming related questions (AHK v1.1 and older)
ItsClint
Posts: 15
Joined: 28 Sep 2018, 05:34

Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

28 Sep 2018, 06:11

Hey there AHK! I've been using ahk scripts for a while but never really went deep into actual "script-land", nor ever registered! It was mostly scripts with one function and nothing else.
I'm trying to send a key to a window, which is simple enough and I managed to do before, but I'd prefer if it could send a key even when the window is inactive,
and I would like to pick which window to send the key to when the script starts, because I'd have multiple instances of this game open, and I'd need to select the one I need the script on, and no other.

That being said, it shouldn't be that hard with ControlSend, but I'm not sure on how to proceed. I explained a bit more in the code itself.

Code: Select all

SetTimer, Routine, 10000

; I need a portion of code that detects the ahk_id of the window I want, and returns the value to the variable MYWINDOW in this case. Or whatever other name.
; I'm looking into winexist, please do tell if there's a better way.
; Basically I'd need something like mywindow := *code that checks ahk_id of the window I'm hovering, or better, that I press a key on/in.*
; The end result should send the key "3" every 10 seconds to that specified window/ahk_id.
; I copied the routine bit from an old ahk forum thread (forgot which one now), the "inside" of the routine is my code.

id := WinExist(%MYWINDOW%)

Routine:
ControlSend,, 3, ahk_id %id%
return

F12:: ; or any other key if f12 is problematic
SetTimer, Routine, off
return
Please excuse code errors, commas and the sort. I'm learning, and I'm a bit rusty.
Thanks in advance.

TL;DR: function that, when a specific key is pressed, detects the ahk_id of the window on focus, to be able to send keystrokes to it even when it becomes inactive or unfocused, while having another copy of that game open that DOESN'T receive the keystrokes.
User avatar
Onimuru
Posts: 107
Joined: 08 Sep 2018, 18:35
Contact:

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

28 Sep 2018, 07:29

Like this:

Code: Select all

#SingleInstance Force
SendMode Input

Exit

F12::
	If !Toggle_Variable	;If not on already.
		ID := WinExist("A")	;The current active window.
	SetTimer, Routine, % ((Toggle_Variable := !Toggle_Variable) ? "10000" : "Off")	;Toggle timer on/off.
	Return

Routine:
	ControlSend, , 3, ahk_id %ID%
	Return
ItsClint
Posts: 15
Joined: 28 Sep 2018, 05:34

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

28 Sep 2018, 08:03

Hey, thanks onimuru. I tested the code but it doesn't appear to send 3 at all. I'm guessing it's because I lack the %id% part, so it doesn't know where to send it. Since it changes every time I reopen the game (or reboot my pc) I can't set a static one.
I'm wondering if you could help me with a window detector, so to speak, every time I open the script.

Basically asking me which window I want to use it on, and after having it on focus, I could press a key (e.g. F3) to mark my selection. After that, it just loops the function of sending a key (in my case, "3") every X seconds (let's say 5 or 10), even when out of focus or inactive, so I can play on the other game window. Hopefully this makes sense.

EDIT: Just noticed you set it to "active window". So I should boot the script, press F12 and it should start sending the key "3" every 10 seconds right? It doesn't though. I don't know why.

EDIT2: Found this old script by girlgamer:

Code: Select all

SetTitleMatchMode, 2
CoordMode, pixel, screen
Coordmode, mouse, screen
DetectHiddenWindows, On

; Hover over one of the windows
SoundBeep, 750
tooltip, place mouse over the window you want to identify. press middle mouse button, 100, 0 
; press the middle mouse button to identify that window
keywait, MButton, D
keywait, MButton
mousegetpos, w1mx, w1my, w1id
; then get the window title from the id
wingettitle, w1title, ahk_id %w1id%
msgbox,0x1020, , This window's id and title are`nId:`t%w1id%`ntitle:`t%w1title%
; with that title find all windows that match that title 
WinGet, winlist, List, %w1title%
; make a displayable string showing the list of ids
str =
loop %winlist%
{    thisid := winlist%A_Index%
     str = %str%`n%thisid%
}
msgbox, Number of matching windows = %winlist%%str%
; then to use any window in the list you simply activate it using it's id
If (winlist)
{	random, thiswin, 1, %winlist% ;<-- pick a random window from the list
	wid := winlist%thiswin%
	msgbox,0x1020,,Activating window#: %thiswin% id: %wid%
	winactivate, ahk_id %wid%
	controlclick,,ahk_id %wid%
}
exitapp
That works, but how would I go about implementing something like that in my script? Thanks.
User avatar
Onimuru
Posts: 107
Joined: 08 Sep 2018, 18:35
Contact:

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

28 Sep 2018, 11:37

The code I gave you works fine, you can test it yourself with:

Code: Select all

#SingleInstance Force
SendMode Input

if !A_IsAdmin
{
	Run *RunAs "%A_ScriptFullPath%"
	ExitApp
}

Exit

F12::
	ID := WinExist("A")	;Gets the ID of the current active window on every press of F12.
	ToolTip % ID, 0, 0
	Return
You need to confirm if ControlSend works with your game. Try:

Code: Select all

#SingleInstance Force
#InstallKeybdHook
SendMode Input
DetectHiddenWindows, On
SetControlDelay, 50	;Test with different values here.

if !A_IsAdmin
{
	Run *RunAs "%A_ScriptFullPath%"
	ExitApp
}

Exit

1::
	ToolTip, Testing %A_ThisHotkey% With ControlSend in window %ID%, 0, 0
	ControlSend, , 3, ahk_id %ID%
	Return

2::
	ToolTip, Testing %A_ThisHotkey% With ControlSend + delay in window %ID%, 0, 0
	ControlSend, , {3 Down}, ahk_id %ID%
	Sleep 500
	ControlSend, , {3 Up}, ahk_id %ID%
	Return

3::
	ToolTip, Testing %A_ThisHotkey% With ControlSendRaw in window %ID%, 0, 0
	ControlSendRaw, , 3, ahk_id %ID%
	Return
So basically, If you can't get ControlSend to work with these very basic examples then you have the option to [1] make the window active, use Send, then restore the window that was previously active. You will notice a flicker, but it should be usable. [2] Look into using virtual keys with DLL calls.
ItsClint
Posts: 15
Joined: 28 Sep 2018, 05:34

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

28 Sep 2018, 12:11

Your code does indeed work, and ControlSend doesn't. I merged your two codes, I get the ID with CTRL+i then test with 1 2 and 3. It does work in notepad, notepad++, in the browser even, not in the game though. So you were right. Didn't expect a 2000s MMO to have any sort of "protection" I guess.

Your option [1] would basically use WinActive ahk_id %ID% and normal Send instead of ControlSend, right? How do I return to the previous active window though?
Also, that rises a small problem, basically I'd need it to keep spacebar pressed the whole time (along with pressing 3 every so often), so what I do is press spacebar, keep it pressed, and tab out; that makes the spacebar "held down" in the game.
So the script would have to account for that too, if I do tab back in.

Edit: I'm leaning more towards your [2] solution. Is it possible with Autohotkey?

Code: Select all

#SingleInstance Force
#InstallKeybdHook
SendMode Input
DetectHiddenWindows, On
SetControlDelay, 50	;Test with different values here.

if !A_IsAdmin
{
	Run *RunAs "%A_ScriptFullPath%"
	ExitApp
}

Exit

^i::
	ID := WinExist("A")	;Gets the ID of the current active window on every press of CTRL+i.
	ToolTip % ID, 0, 0
	Return

1::
	ToolTip, Testing %A_ThisHotkey% With ControlSend in window %ID%, 0, 0
	ControlSend, , 3, ahk_id %ID%
	Return

2::
	ToolTip, Testing %A_ThisHotkey% With ControlSend + delay in window %ID%, 0, 0
	ControlSend, , {3 Down}, ahk_id %ID%
	Sleep 500
	ControlSend, , {3 Up}, ahk_id %ID%
	Return

3::
	ToolTip, Testing %A_ThisHotkey% With ControlSendRaw in window %ID%, 0, 0
	ControlSendRaw, , 3, ahk_id %ID%
	Return
^This code works. With anything but the game, it works.

Edit2: context. My spacebar is my attack key, 3 is the key used to attract monsters. So if I keep spacebar pressed, I keep attacking, and I use 3 when monsters respawn, which is about 8-12 seconds. I averaged at 10. Just so you could have a better understanding.

Edit3: Normal send doesn't seem to work either, neither does SendInput nor SendPlay. I guess I'm out of luck. All work in the browser or other apps.

Code: Select all

#SingleInstance Force
#InstallKeybdHook
SendMode Input
DetectHiddenWindows, On
SetControlDelay, 50	;Test with different values here.

if !A_IsAdmin
{
	Run *RunAs "%A_ScriptFullPath%"
	ExitApp
}

Exit

^i::
	ID := WinExist("A")	;Gets the ID of the current active window on every press of CTRL+i.
	ToolTip % ID, 0, 0
	Return

1::
	ToolTip, Testing %A_ThisHotkey% With Send in window %ID%, 0, 0
	WinActivate, ahk_id %ID%
	SendInput {3}
	Return
That's the code by the way in case you were curious. Mostly yours, I just changed the WinActivate part and stripped the other 2 functions. Send/SendInput/SendRaw don't work, with or without {} braces around the 3.

Edit4: The code does work in administrator mode in the game, but it doesn't work for the hotkey; in other words, it does type in the in-game chat for example, but it doesn't execute the hotkey. That's with SendInput + WinActivate.


Thanks for your immense help so far!
ItsClint
Posts: 15
Joined: 28 Sep 2018, 05:34

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

29 Sep 2018, 06:07

I feel like this deserves a new post, because it's progress.

I opted for a MouseClick (clicking the hotkey) instead of sending 3 (the hotkey itself); it works!

Code: Select all

#SingleInstance Force
#InstallKeybdHook
SendMode Input
DetectHiddenWindows, On
SetControlDelay, 50	;Test with different values here.

if !A_IsAdmin
{
	Run *RunAs "%A_ScriptFullPath%"
	ExitApp
}

Exit

^i::
	ID := WinExist("A")	;Gets the ID of the current active window on every press of CTRL+i.
	ToolTip % ID, 0, 0
	Return

1::
	ToolTip, Testing %A_ThisHotkey% With ControlClick in window %ID%, 0, 0
	WinActivate, ahk_id %ID%
	Sleep 500
	MouseClick, right, 797, 906
	Return


2::
	MouseGetPos, xpos, ypos 
	MsgBox, The cursor is at X%xpos% Y%ypos%.
	Return
I used MouseGetPos to get my x and y for the hotkey, and I just input that for MouseClick.
Now, is there a way, like ControlSend, to send the click "silently", without activating the window? Or something that returns focus to the previously active window.
The last part will be loop it all with a timer of 5-10 seconds.

Edit: Aaaand it doesn't. Only works if it's already the current active window, despite having WinActivate. Pressing the hotkey "1" does activate the window and apparently does click where it's supposed to, but it doesn't ACTUALLY activate the hotkey.
If I press that another time with the window already active, it does work. Even with 4000 ms sleep between actions.
In contrast, even if it's unfocused and I do manually right click, the hotkey does work. Doesn't with the script. No clue why that might be.

Thanks again to anyone willing to help :)
User avatar
Onimuru
Posts: 107
Joined: 08 Sep 2018, 18:35
Contact:

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

29 Sep 2018, 19:32

Strange that you are able to send clicks but not keyboard inputs. I tried to do exactly what you're doing at one point for a game I play but I gave up in the end, too much of a headache. Here's the code I tried before I gave up:

Code: Select all

;[1]
;v::
;	SetControlDelay -1
;	ControlFocus, , ahk_class LaunchUnrealUWindowsClient
;	ControlClick, x1665 y15, ahk_class LaunchUnrealUWindowsClient,  ,  ,  ,  NA
;	Return

;[2]	Ignores xy
;v::
;	ID := WinExist("ahk_class LaunchUnrealUWindowsClient")
;	PostClick2(1665, 15, ID)
;	return

;PostClick2(x, y, ID)
;{
;	lParam := x & 0xFFFF | (y & 0xFFFF) << 16 
;	PostMessage, 0x201, 1, %lParam%,, ahk_id %ID% ;WM_LBUTTONDOWN 
;	PostMessage, 0x202, 0, %lParam%,, ahk_id %ID% ;WM_LBUTTONUP 
;	return
;}

;[3]	Ignores xy
;v::
;	ID := WinExist("ahk_class LaunchUnrealUWindowsClient")
;	PostClick3(1665, 15, ID)
;	return

;PostClick3(x, y, ID)
;{
;  lParam := x & 0xFFFF | (y & 0xFFFF) << 16 
;  DllCall("SendMessage", "UInt", ID, "UInt", 0x201, "UInt", 1, "UInt", lParam)
;  DllCall("SendMessage", "UInt", ID, "UInt", 0x202, "UInt", 0, "UInt", lParam)
;  return
;}

;[4]	Ignores xy
;v::
;	ID := WinExist("ahk_class LaunchUnrealUWindowsClient")
;	ControlSend, , {Alt}, ahk_class LaunchUnrealUWindowsClient
;	c_F(1665, 15, ID)	;Click, 1665, 15		;Channel menu.
;	Sleep 350
;	c_F(1665, 55, ID)	;Click, 1665, 55		;Channel 2.
;	Sleep 2000
;	ControlSend, , {Alt}, ahk_class LaunchUnrealUWindowsClient
;	Sleep 1000
;	c_F(1665, 15, ID)	;Click, 1665, 15		;Channel menu.
;	Sleep 350
;	c_F(1665, 72, ID)	;Click, 1665, 72		;Channel 3.
;	Return

;c_F(x, y, ID)
;{
;	lParam := x | (y << 16)
; 
;	;SendMessage, 0x086, 0x00000000, 0x00000000, , %ID% 0x00040708	;NCACTIVATE SEND
;	;SendMessage, 0x006, 0x00000000, 0x00000000, , %ID% 0x00040708	;ACTIVATE SEND
;	;SendMessage, 0x01C, 0x00000000, 0x00001774, , %ID% 0x00040708	;ACTIVATEAPP SEND
;	;SendMessage, 0x281, 0x00000000, 0xC000000F, , %ID% 0x00040708	;IME_SETCONTEXT SEND
;	 
;	SendMessage, 0x084, 0x00000000, %lParam%, , ahk_id %ID% 0x00040708		;NCHITTEST SEND
;	SendMessage, 0x020, 0x00040708, 0x02040001, , ahk_id %ID% 0x00040708	;SETCURSOR SEND
;	PostMessage, 0x200, 0x00000000, %lParam%, , ahk_id %ID% 0x00040708		;WM_MOUSEMOVE
;	Sleep 250
;	PostMessage, 0x201, 0x00000002, %lParam%, , ahk_id %ID% 0x00040708		;WM_LBUTTONDOWN
;	SendMessage, 0x084, 0x00000000, %lParam%, , ahk_id %ID% 0x00040708		;NCHITTEST SEND
;	SendMessage, 0x020, 0x00040708, 0x02050001, , ahk_id %ID% 0x00040708	;SETCURSOR SEND
;	PostMessage, 0x202, 0x00000000, %lParam%, , ahk_id %ID% 0x00040708		;WM_LBUTTONUP
;	;DLLCall("SetCursorPos", "int", x, "int", y)
;}
In my case, I was able to send click messages but because of the way the UI is coded, I was unable to update the mouse position so I can't tell it where to click. I may come back and try this again sometime.
ItsClint
Posts: 15
Joined: 28 Sep 2018, 05:34

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

30 Sep 2018, 18:01

I wrote a full-on reply and I accidentally closed the tab before sending it. Welp.

I made it work with mousemove + sleep + mouseclick, it's unorthodox but it works. Fiddled with the sleep and the mousemove speed, 150ms and "5" work fine.
Would something like this work as a loop? I'm trying to click that spot in the window every 4 seconds for a long period of time, 10000 is just an exaggeration, I'm never gonna get there, it's just to symbolize "infinite". That's about 11 hours if my calculations are correct. More than long enough. Problem is, I'm missing one bit. I'd need it to keep spacebar pressed for the whole duration, after clicking CTRL+O (or whatever hotkey to be honest). I could add another loop that gets activated with the same hotkey maybe...? Not sure. I'm testing things and I'll report back once I find a solution... or I don't.

Code: Select all

#SingleInstance Force
#InstallKeybdHook
DetectHiddenWindows, On

^i::
	ID := WinExist("A")	;Gets the ID of the current active window on every press of CTRL+i.
	ToolTip % ID, 0, 0
	Return
	
^o::
	WinActivate, ahk_id %ID%
	Loop {
	MouseMove, 797, 906, 5
	Sleep 150
	MouseClick, right, 797, 906
	n++
	Sleep 4000
	} Until (n > 10000)
	Return
I stripped the admin part from your code. What would that do anyway? I'm guessing if I didn't have/give it admin rights it would rerun itself as... something? No idea what A_ScriptFullPath would be.

Thanks for your help, really made me think outside the box and try new things. Appreciated.


Edit: Why does controlsend not work, in your opinion? I tried it, it does indeed send the key 3, and if I open the chat of the game it does send 3 in the chat, but the hotkey corresponding to 3 doesn't do what it's supposed to. The physical keypress obviously works, and normal send also works (with these settings). It might help that I changed from "Game IME" to "External IME", and I googled up IME, apparently it's input method editor. Whatever I guess.

Code: Select all

#SingleInstance, Force
#InstallKeybdHook
DetectHiddenWindows, On
SetKeyDelay, 100, 200

RandSleep(x,y) {
Random, rand, %x%, %y%
Sleep %rand%
}

RemoveToolTip: ; This guy removes it.
ToolTip
return

^i::
	ID := WinExist("A") ; Gets the ID of the current active window on every press of CTRL+i.
	ToolTip, % ID, 0, 0
	SetTimer, RemoveToolTip, -3000 ; ToolTip timer. Can't stand that tooltip being everpresent.
	Return
	
m::
	ControlSend, ahk_parent, {3}, ahk_id %ID%
	Return
	
n:: 
	WinActivate, ahk_id %ID%
	Send 3
	Return
Don't mind RandSleep. I'd use it for random sleep in case I ever get to make a loop out of this. Shouldn't affect anything.

Edit2: confirmed ControlSend does work, but doesn't activate the hotkey, no matter the hotkey. Also works in background; if I open the chatbox and press m (which should press 3) it works, and does print out 3, even when unfocused. So the key is being sent, but the game doesn't recognize it as a hotkey, or, at the very least, it treats it differently from a regular, physical, keypress, and is indeed different from the input a "Send" command. Because that one works too.
What's the difference between ControlSend and Send? Both seem to work in the same way, but Send activates the hotkey, ControlSend doesn't.

Edit3: Apparently, the game I'm trying it on has no "control", so ControlSend has nothing to send the key to.

Image

This is the output of Window Spy. The control shows no "ClassNN" but it does show "Text", but it's the same as the window title as far as I know. It's just cut off.
Am I out of luck trying to send keystrokes to this window in the background?
ItsClint
Posts: 15
Joined: 28 Sep 2018, 05:34

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

03 Oct 2018, 13:42

Still struggling with this. Anyone has some code I could throw at this game to see if it works? I'm kinda stumped.
ItsClint
Posts: 15
Joined: 28 Sep 2018, 05:34

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

04 Oct 2018, 23:14

I opened a reddit thread a couple days ago to see if I could get more info.
I'm gonna be adding more info in both places.

As of now, I know for a fact that:

- Send, SendEvent, SendInput work as hotkeys and in game chat, but those only work when the game is in focus / is the active window.
- SendPlay, ControlSend, PostMessage, SendMessage work in the game chat only, whether the game is in focus or not. They don't activate hotkeys.

No clue where to go from here. I really hope someone knowledgeable can come salvage me from this mess. I've read through a lot of old posts about PostMessage and such, like these:

https://autohotkey.com/board/topic/482- ... me-window/
https://autohotkey.com/board/topic/4702 ... etectable/
https://autohotkey.com/board/topic/785- ... utohotkey/

and probably more I forget now. I can't seem to find a solution.
Maybe AutoHotKey just can't do it?
ItsClint
Posts: 15
Joined: 28 Sep 2018, 05:34

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

15 Oct 2018, 06:12

Still looking for a solution but I really lost energy to continue this for the time being. I'm working on it on and off because at this point the answer might just be beyond AHK's capabilities.

Bump, and hopefully someone more knowledgeable than me can explain what I'm doing wrong :(
Ruevil2
Posts: 173
Joined: 14 Jul 2014, 10:39

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

16 Oct 2018, 14:04

ItsClint wrote:
15 Oct 2018, 06:12
Still looking for a solution but I really lost energy to continue this for the time being. I'm working on it on and off because at this point the answer might just be beyond AHK's capabilities.

Bump, and hopefully someone more knowledgeable than me can explain what I'm doing wrong :(
Try using SetKeyDelay, 10, 10 as a directive at the top of your script(this affects the ControlSend command). I suspect that the game client doesn't like the speed at which the key is being pressed and released. Most games use an "input polling method" to capture keyboard input and inputs that are too fast can fall through the gaps.

Check this topic and #3 in this how to and see if adding a 'press delay' makes the game recognize your keypresses as hotkeys.
ItsClint
Posts: 15
Joined: 28 Sep 2018, 05:34

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

16 Oct 2018, 14:11

Ruevil2 wrote:
16 Oct 2018, 14:04
ItsClint wrote:
15 Oct 2018, 06:12
Still looking for a solution but I really lost energy to continue this for the time being. I'm working on it on and off because at this point the answer might just be beyond AHK's capabilities.

Bump, and hopefully someone more knowledgeable than me can explain what I'm doing wrong :(
Try using SetKeyDelay, 10, 10 as a directive at the top of your script(this affects the ControlSend command). I suspect that the game client doesn't like the speed at which the key is being pressed and released. Most games use an "input polling method" to capture keyboard input and inputs that are too fast can fall through the gaps.

Check this topic and #3 in this how to and see if adding a 'press delay' makes the game recognize your keypresses as hotkeys.
I appreciate your reply, but that won't help I'm afraid. I set key delay as high as "100, 200" and it still won't recognize it as a hotkey. It does work in the chatbox of the game, but that's it. Normal send (with the window being active) works for both with the same key delay. I reckon it's a different problem entirely...
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

16 Oct 2018, 14:20

if varying the delay doesn't get u anywhere, chances are u wont get ControlSend to work at all
games can be coded to discard input while unfocused. Its possible thats whats happening when the chatbox isnt open
ItsClint
Posts: 15
Joined: 28 Sep 2018, 05:34

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

16 Oct 2018, 14:32

swagfag wrote:
16 Oct 2018, 14:20
if varying the delay doesn't get u anywhere, chances are u wont get ControlSend to work at all
games can be coded to discard input while unfocused. Its possible thats whats happening when the chatbox isnt open
While I agree, controlsend with the same settings as send doesn't work even while the window is active. This game is so old I doubt it has any sort of protection, but even so, why would send work but not controlsend, with the same keydelay and window conditions...? That's why I've been stumped for a while. But still, you're probably right, I won't be able to make controlsend work most likely.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

16 Oct 2018, 14:54

2004 isnt that long ago and it would be naive to assume a developer that exclusively specializes in MMOs wouldn't incorporate a simple countermeasure to negate the very thing most detrimental to their game - botting.
the reason why send would work, but controlsend wouldnt, was mentioned already: the game is likely discarding input while unfocused
Ruevil2
Posts: 173
Joined: 14 Jul 2014, 10:39

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

16 Oct 2018, 15:02

swagfag wrote:
16 Oct 2018, 14:54
2004 isnt that long ago and it would be naive to assume a developer that exclusively specializes in MMOs wouldn't incorporate a simple countermeasure to negate the very thing most detrimental to their game - botting.
the reason why send would work, but controlsend wouldnt, was mentioned already: the game is likely discarding input while unfocused
I don't think that is the case here. It was mentioned earlier that ControlSend does work(and while unfocused) but only to the chat window. So we know that the game isn't ditching ALL inputs while unfocused.
ItsClint wrote:
30 Sep 2018, 18:01
Edit2: confirmed ControlSend does work, but doesn't activate the hotkey, no matter the hotkey. Also works in background; if I open the chatbox and press m (which should press 3) it works, and does print out 3, even when unfocused.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

16 Oct 2018, 16:39

yes, im aware of this, but unless the goal here was to chat instead of controlling a character, i fail to see how this makes any difference whatsoever
ItsClint
Posts: 15
Joined: 28 Sep 2018, 05:34

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

16 Oct 2018, 16:46

Ruevil2 wrote:
16 Oct 2018, 15:02
swagfag wrote:
16 Oct 2018, 14:54
2004 isnt that long ago and it would be naive to assume a developer that exclusively specializes in MMOs wouldn't incorporate a simple countermeasure to negate the very thing most detrimental to their game - botting.
the reason why send would work, but controlsend wouldnt, was mentioned already: the game is likely discarding input while unfocused
I don't think that is the case here. It was mentioned earlier that ControlSend does work(and while unfocused) but only to the chat window. So we know that the game isn't ditching ALL inputs while unfocused.
ItsClint wrote:
30 Sep 2018, 18:01
Edit2: confirmed ControlSend does work, but doesn't activate the hotkey, no matter the hotkey. Also works in background; if I open the chatbox and press m (which should press 3) it works, and does print out 3, even when unfocused.
I mean, 2004 IS long ago... that's 14 years... but even then, the client I'm using is specifically stripped of any AC measure, as far as I'm aware. Unless this check is in the game exe itself, of course.
And to Ruevil2: Precisely.
swagfag wrote:
16 Oct 2018, 16:39
yes, im aware of this, but unless the goal here was to chat instead of controlling a character, i fail to see how this makes any difference whatsoever
That means the game isn't ignoring the input, maybe it just doesn't know what to do with it, or as I read on older forums, it's being sent to the "wrong part" of the window/game (like how Winamp has to have ahk_parent to make hotkeys work with ControlSend in background, although that didn't fix it for the game).

Thing is, I'm absolutely clueless in how I should go about fixing this. I appreciate the more active discussion though, I've been struggling for a while, thanks for your input you guys!
Ruevil2
Posts: 173
Joined: 14 Jul 2014, 10:39

Re: Send keystrokes to a single inactive or unfocused game window, with multiple instances of the game open

16 Oct 2018, 17:05

swagfag wrote:
16 Oct 2018, 16:39
yes, im aware of this, but unless the goal here was to chat instead of controlling a character, i fail to see how this makes any difference whatsoever
Seriously? If the game was programatically ditching ALL inputs, there would be nothing we could do to make it register keypresses without altering the client. Also it's likely that the chat window becomes the top level(and only) control, allowing ControlSend to work as long as it's topmost, which fits all of the behaviors we see here. When it's not topmost/enabled AHK is simply failing to send the command. This leads me to believe that it is the syntax of the ControlSend command that is not proper(but is when it finds a control to send to).

For example, using DllCall to use a different WM post msg or Class_DD(WinRing0 alternative) to simulate hardware level inputs.

There are a few things left to try here.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: todd and 57 guests