What I do in this function is save the current window before updating the GUI, then reactivating the previous window in order to keep working with it. The problem is... it doesn't work. Whenever I'm using this function, trying to send or paste text to the primary window fails. The speaker beeps, because, I think, AHK is trying to send text to the OSD GUI, which shouldn't be happening.
I'll paste the whole function here. If somebody could point me to the source of the problem, I'd be very grateful.
Thanks!
Code: Select all
OSD( cmd := "--", params := "" ) {
Static x := 33
Static y := 33
Static text := ""
Static fgcolor := "white"
Static bgcolor := "blue"
Static font := "Inconsolata"
Static fsize := 12
hw := WinActive("A") ; here is where I save the current window
Switch cmd
{
Case "INIT":
Gui, OSD:New, +AlwaysOnTop -Caption +ToolWindow
Gui, OSD:Color, blue
Gui, OSD:Font, cWhite s12, Inconsolata
Gui, OSD:Margin, 6
Case "--":
Sleep % params
Gui, OSD:Destroy
Default:
text .= cmd "`n"
if IsObject(params) {
for e, v in params {
%e% := v
Gosub OSD_SetVars
}
}
Gui, OSD:+LastFoundExist
if not WinExist()
OSD("INIT")
Gui, OSD:Add, Text, Y+4, % cmd
Gui, OSD:Show, X%x% Y%y% Autosize
}
WinActivate, %hw% ; restoring the active window
Sleep 333 ; I put this in just in case
return
OSD_SetVars:
Gui, OSD:Color, %bgcolor%
Gui, OSD:Font, c%fgcolor% s%fsize%, %font%
return
}