send keystrokes to a window in the background but i cant find the window name

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Ulfric Stormcloak
Posts: 39
Joined: 28 Apr 2017, 23:26

send keystrokes to a window in the background but i cant find the window name

20 Jul 2017, 23:41

Code: Select all

wintitle =
SetTitleMatchMode, 2
#SingleInstance Force

IfWinExist %wintitle% 
{
   loop
   {
        Controlsend,,{v}, %wintitle% 
        sleep 500
   }
}
Return

F5:: ExitApp

Hi

I have this script for sending keystrokes to a window in the background but i can write the wintitle because the window title has some weird characters in it name which you cant type on notepad so what can i do ?

Also is my script correct ?
thank you.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: send keystrokes to a window in the background but i cant find the window name

21 Jul 2017, 00:54

Some code ideas:

Code: Select all

q::
;WinGetTitle, vWinTitle, % "ahk_id " hWnd
WinGetTitle, vWinTitle, A
Clipboard := vWinTitle
MsgBox, % vWinTitle
return

w::
;DetectHiddenWindows, On
DetectHiddenWindows, Off
WinGet, vWinList, List
vOutput := ""
Loop, % vWinList
{
	hWnd := vWinList%A_Index%
	WinGetTitle, vWinTitle, % "ahk_id " hWnd
	;WinGetClass, vWinClass, % "ahk_id " hWnd
	;WinGet, vPID, PID, % "ahk_id " hWnd
	vOutput .= hWnd " " vWinTitle "`r`n"
}
Clipboard := vOutput
MsgBox, % vOutput
return

e::
vText := "how to store special chars like: " Chr(8730) ;square root sign
MsgBox, % vText
return

r:: ;replace non-Ascii characters (appears accurate but not thoroughly tested)
vText := Clipboard
vDQ := Chr(34)
vOutput := ""
VarSetCapacity(vOutput, StrLen(vText)*2*2)
Loop, Parse, vText
{
	vChar := A_LoopField
	vIsAscii := !!(Ord(vChar) <= 127)
	(vChar = vDQ) && vChar .= vDQ
	(vChar = "`t") && vChar := "``t"
	(vChar = "`r") && vChar := "``r"
	(vChar = "`n") && vChar := "``n"
	if (A_Index=1 && vIsAscii)
		vPfx := vDQ
	else if (A_Index=1) || (vIsAscii && vIsAscii2)
		vPfx := ""
	else if vIsAscii && !vIsAscii2
		vPfx := " " vDQ
	else if !vIsAscii && vIsAscii2
		vPfx := vDQ " "
	else if !vIsAscii && !vIsAscii2
		vPfx := " "
	vIsAscii2 := vIsAscii
	if vIsAscii
		vOutput .= vPfx vChar
	else
		vOutput .= vPfx "Chr(" Ord(vChar) ")"
}
Clipboard := vOutput
MsgBox, % "done"
return
Cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, jaka1 and 173 guests