Sending key to inactive & active window.

Ask gaming related questions (AHK v1.1 and older)
Vexides
Posts: 3
Joined: 24 Jun 2021, 18:33

Sending key to inactive & active window.

24 Jun 2021, 18:40

Fixed.
Last edited by Vexides on 25 Jun 2021, 17:54, edited 1 time in total.
Rohwedder
Posts: 7623
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Sending key to inactive & active window.

25 Jun 2021, 05:00

Hallo,
always take the first step before the second! Before you start a longer script, test if Autohotkey can distinguish your two tabs.
Try:

Code: Select all

q::
WinGet, GotaPID, List, ahk_exe javaw.exe
Loop,% GotaPID
	MsgBox,% "GotaPID" A_Index ": " GotaPID%A_Index%
Return
Vexides
Posts: 3
Joined: 24 Jun 2021, 18:33

Re: Sending key to inactive & active window.

25 Jun 2021, 10:05

Rohwedder wrote:
25 Jun 2021, 05:00
Hallo,
always take the first step before the second! Before you start a longer script, test if Autohotkey can distinguish your two tabs.
Try:

Code: Select all

q::
WinGet, GotaPID, List, ahk_exe javaw.exe
Loop,% GotaPID
	MsgBox,% "GotaPID" A_Index ": " GotaPID%A_Index%
Return
Yes! They both have different PIDs.
Rohwedder
Posts: 7623
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Sending key to inactive & active window.

25 Jun 2021, 12:03

Then try:

Code: Select all

#Warn
SetTitleMatchMode, 2
End::ExitApp
q::
Hotkey, *~t, Toggle
WinGet, GotaPID, List, ahk_exe javaw.exe
Return
*~t::
SetKeyDelay, 1
IF WinActive("ahk_pid " GotaPID1)
	ControlSend, , t, ahk_pid %GotaPID2%
Else
	ControlSend, , t, ahk_pid %GotaPID1%
sleep 10
return
Vexides
Posts: 3
Joined: 24 Jun 2021, 18:33

Re: Sending key to inactive & active window.

25 Jun 2021, 12:16

Rohwedder wrote:
25 Jun 2021, 12:03
Then try:

Code: Select all

#Warn
#Persistent
SetTitleMatchMode, 2
End::ExitApp
q::
Hotkey, *~$t, Toggle
WinGet, GotaPID, List, ahk_exe javaw.exe
Return
*~$t::
SetKeyDelay, 1
ControlSend, , t, ahk_pid %GotaPID1%
ControlSend, , t, ahk_pid %GotaPID2%
sleep 10
return
This code isn't sending any key in any of those tabs.
Rohwedder
Posts: 7623
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Sending key to inactive & active window.

27 Jun 2021, 05:06

Here this works with two Notepad windows:

Code: Select all

q:: ;opens 2 Notepad windows side by side 
Loop, 2
{
	Run, Notepad.exe
	Sleep, 500
	WinMove, A,,% 500 * (A_Index-1),0 ,500, 500
}
Return
~w:: ;writes w each also in the other Notepad window
WinGet, ID, List, ahk_exe Notepad.exe
; ToolTip,% ID1 " > " ID2
IF WinActive("ahk_id " ID1)
	ControlSend,, w, ahk_id %ID2%
Else
	ControlSend,, w, ahk_id %ID1%
Return
or:

Code: Select all

Loop, 2
{ ;opens 2 Notepad windows side by side
	Run, Notepad.exe
	Sleep, 500
	WinMove, A,,% 500 * (A_Index-1),0 ,500, 500
}
WinGet, ID, List, ahk_exe Notepad.exe
Loop
{ ;writes also in the other Notepad window
	Input, Key, VCL1
	IF WinActive("ahk_id " ID1)
		ControlSend,, {%Key%}, ahk_id %ID2%
	Else
		ControlSend,, {%Key%}, ahk_id %ID1%
}
Return

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 67 guests