Jump to content

Send with lose focus?

Recommended Posts


In front: Im sorry if my English is bad. Im German.

I was trying to do something i could send text to a chat with a hotkey. I was able to manage that part somehow. (attach) But i want to be able to send this text without have to focus on the window with the chat. I was trying to use ControlSend, but it seems im way to stupid to understand how this thing works at all. Also i believe that the WIndow Info gives me the hole window instead of the chatbox. The chat is at the panel from PhantomBot (a Twitch ChatBot). I use him on localhost in google chrome browser.

I want this to be able to manage my chat a little while im playing. (And no, this is not for a game itself, it's just for while im playing, so the script or what u call it should not interact with the game... so i think this request is not against the rules.) I startet streaming on Twitch and if i want to type a command in the chat like "!uptime", i would need to pause the game and switch over. Or on older games even minimize the game. Wich i would love to avoid with this.

Hopefully someone knows how to manage this... i have TeamViewer 12 if needed.


Information from "(Frozen) AutoIt v3 Window Info" when with mouse over ChatBox.

>>>> Window <<<<
Title: PhantomBot Control Panel - Google Chrome
Class:    Chrome_WidgetWin_1
Position:    -1288, -264
Size:    1296, 1040
Style:    0x17CF0000
ExStyle:    0x00000100
Handle:    0x00080186

>>>> Control <<<<
Class:    Chrome_RenderWidgetHostHWND
Instance:    1
ClassnameNN:    Chrome_RenderWidgetHostHWND1
Advanced (Class):    [CLASS:Chrome_RenderWidgetHostHWND; INSTANCE:1]
ID:    338532544
Text:    Chrome Legacy Window
Position:    0, 90
Size:    1280, 932
ControlClick Coords:    1106, 823
Style:    0x56300000
ExStyle:    0x00000020
Handle:    0x00120258

>>>> Mouse <<<<
Position:    -174, 657
Cursor ID:    0
Color:    0x141414

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
Chrome Legacy Window

Thanks to anyone reading this and/or (try) helping.


Share this post

Link to post
Share on other sites

Hello @Ryok und willkommen to the forum ;)

Controlclick and Controlsend are not very reliable to use for interacting with websites inside web browsers.

Instead if you want to interact with a website you need to use the functions included with the UDF related to your web browser (so Chrome UDF for you), or use object programming.

But in either case this is usually a bit complex to do.

I think in your case a much more simple solution would be to connect to your twitch chat channel using IRC.

You can find here how to connect to your twitch channel using IRC:


You can test if your account login / pass to your twitch channel are correct by using an irc client like HexChat.

Then use an IRC UDF (search the forum) to use autoIT to connect to your twitch IRC channel.

Then you can use a hotkey function in autoit like _IsPressed to send anything in the chat :)

Edited by Neutro

Share this post

Link to post
Share on other sites

Well I had some spare time and wanted to give it a try so here you go :D

#include <IRC.au3>
#include <Misc.au3>

; Allow some TCP lag
Opt("TCPTimeout", 500)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Twitch chat hotkey", 381, 436, 192, 124)
GUISetFont(10, 400, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("Twitch chat hotkey", 128, 8, 153, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Twitch username:", 16, 88, 144, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("", 176, 88, 185, 24)
$Label3 = GUICtrlCreateLabel("OAuth password:", 16, 128, 141, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("oauth:", 176, 128, 185, 24)
$Button1 = GUICtrlCreateButton("Get OAuth password", 88, 176, 201, 41)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("Twitch channel:", 16, 240, 128, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Input3 = GUICtrlCreateInput("kolento", 160, 240, 201, 24)
$Label5 = GUICtrlCreateLabel("Message:", 16, 288, 81, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Input4 = GUICtrlCreateInput("Kappa hello guys Kappa", 112, 288, 249, 24)
$Button2 = GUICtrlCreateButton("Connect", 104, 376, 193, 41)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label6 = GUICtrlCreateLabel("Status: disconnected", 136, 336, 128, 20)
GUICtrlSetColor(-1, 0xFF0000)
$Label7 = GUICtrlCreateLabel("Press F10 once connected to send the message", 56, 48, 291, 20)
#EndRegion ### END Koda GUI section ###

;restore previous values if the software has already been used

if RegRead("HKCU\Software\TwitchChatHotkey", "username") <> "" Then

    GUICtrlSetData($Input1, RegRead("HKCU\Software\TwitchChatHotkey", "username"))
    GUICtrlSetData($Input2, RegRead("HKCU\Software\TwitchChatHotkey", "password"))
    GUICtrlSetData($Input3, RegRead("HKCU\Software\TwitchChatHotkey", "channel"))
    GUICtrlSetData($Input4, RegRead("HKCU\Software\TwitchChatHotkey", "message"))


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        Case $Button1
        Case $Button2
            GUICtrlSetState($Button2, $GUI_DISABLE)

Func connect()

    GUICtrlSetData($Label6, "Status: connecting...")
    GUICtrlSetColor($Label6, $COLOR_BLUE)

    $username = GUICtrlRead($Input1)
    $password = GUICtrlRead($Input2)
    $channel = StringLower(GUICtrlRead($Input3))
    $message = GUICtrlRead($Input4)

    ;backup info for future usage

    Regwrite("HKCU\Software\TwitchChatHotkey", "username", "REG_SZ", $username)
    Regwrite("HKCU\Software\TwitchChatHotkey", "password", "REG_SZ", $password)
    Regwrite("HKCU\Software\TwitchChatHotkey", "channel", "REG_SZ", $channel)
    Regwrite("HKCU\Software\TwitchChatHotkey", "message", "REG_SZ", $message)

    ;Start Up Networking

    ; Connect to IRC. Send Password, if any. Declare User Identity.
    Local $Sock = _IRCConnect("irc.chat.twitch.tv", 6667, $username, 0, $username, $password)

    ; Prepare to Receive Data
    Local $sRecv = ""

    ; Start Loop
    While 1

        ; Receive Data
        $sRecv = _IRCGetMsg($Sock)

        ; Split Data into Commands and Parameters for Processing
        Local $sTemp = StringSplit($sRecv, " ")

        ; If Not Usable, then Skip this Data
        If $sTemp[0] <= 2 Then ContinueLoop

        ; Decide What To Do Based on Received Data
        Switch $sTemp[2]

            ; On Server Welcome
            Case $RPL_WELCOME

                ; Join channel
                _IRCChannelJoin($Sock, "#" & $channel)

                GUICtrlSetData($Label6, "Status: connected")
                GUICtrlSetColor($Label6, $COLOR_GREEN)

                While 1

                    If _IsPressed(79) Then

                        $message = GUICtrlRead($Input4)

                        _IRCRaw($Sock, "PRIVMSG #" & $channel & " :" & $message)

                        while _IsPressed(79)

                            ;do nothing when the key is kept pressed to avoid chat flood, so the message is only sent once



                    $nMsg = GUIGetMsg()

                    If $nMsg = $GUI_EVENT_CLOSE Then

                        ; Disconnect

                        ; Shutdown Networking






EndFunc   ;==>connect

To compile this you will need the IRC UDF that you can download here

I also attached a compiled version here:  Twitch chat message hotkey.exe

Enjoy ;)

Edited by Neutro

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now