Trying to automate Chromecast, problem controlling Chrome

If you have a question or need help, this is the place to be.
Post Reply
wysocki
Experienced User
Posts: 70
Joined: Mon Nov 23, 2015 9:23 pm
Location: Los Angeles area

Trying to automate Chromecast, problem controlling Chrome

Post by wysocki » Tue Sep 12, 2017 9:36 pm

I'd ultimately like to integrate casting into my HTPC configuration, but I'm stuck right off the bat with a simple problem: I can't control keystrokes to Chrome! I just started with a simple macro to right click in Chrome and select CAST, then select my chosen device, but it seems like the Send Keystrokes action doesn't do anything.

Code: Select all

Find Window: chrome.exe
Bring to Front
Move cursor to: x:300, y:300
Right Mouse Click
Send Keystrokes: c
The Send Keystrokes doesn't appear to do anything, nor does "Send Keystrokes: {down}{down}{down}{down}{down}".
If I add Change cursor position by x:50, y140 then the whole right-click-menu moves down with it instead of just moving the mouse to a selection.

Any ideas where I'm going wrong here? (has anyone done anything differently to control casting?)

User avatar
kgschlosser
Site Admin
Posts: 5498
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Trying to automate Chromecast, problem controlling Chrom

Post by kgschlosser » Wed Sep 13, 2017 12:40 am

send keystrokes does work. but you have to tell it where to send them. to do this you would use the FindWindow action. place it right before the send keystrokes. But there is a hitch. you have to specify the specific button/menu/whatever so when you use the Find Window. Use the little target thingie to target the specific item. So if it is a button then target it. and if you want to press said button then add the send keystrokes action right after the Find Window action with {Enter} in the keys to send box. This will mimic pressing the button down..

Now. just to let ya know. the window you want to control does not have to be in focus it can be in the background.

If you want to access something like a menu you would target the menu. Use the send keystrokes to send {Enter}{Down}{Enter} and add the {Down} as many times as it is necessary to get to the item you want and the final {Enter} selects that item
If you like the work I have been doing then feel free to Image

wysocki
Experienced User
Posts: 70
Joined: Mon Nov 23, 2015 9:23 pm
Location: Los Angeles area

Re: Trying to automate Chromecast, problem controlling Chrome

Post by wysocki » Wed Oct 11, 2017 1:06 am

The "hitch" you mention is a problem. I run this command to start Pandora playing a channel with NO browser controls visible:

Code: Select all

chrome.exe --new-window --app=https://www.pandora.com/station/play/1599767317517984386
Then when the page is loaded, I can RIGHT-click on any part of the browser window and one of the resulting popup menu choices is CAST which I want to select. So I can't target any particular "thingie" with FindWindow.

Even if this would work, I'm afraid this project is virtually impossible to do. That's because once I click on CAST from the popup menu, A new menu with my Casting Target Choices comes up at the top of the browser window and it has a variable list of casting destinations for me to select from. This list appears in no logical, repeatable order and it is not keyboard accessible - you must choose a line with the mouse.

All in all, I'm afraid this is an impossible task. Has anyone been able to automate Google casting (even with tools other than EG)?

User avatar
kgschlosser
Site Admin
Posts: 5498
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Trying to automate Chromecast, problem controlling Chrome

Post by kgschlosser » Wed Oct 11, 2017 4:56 am

well I now there is this plugin. Tho I do not know how much of what you can do with it. By since the author of the plugin is still around you may want to drop a line in there asking if it doesn't do what you need it to. I believe it works via an extension you have to install in chrome.

The big issue now a days is alot of software companies (especially the large ones) are creating whole custom UI's for their programs. a typical rule of thumb is, if you can theme it then you can't select specific items in it. We only have a way of identifying specific control elements if the UI uses the standard ones that are installed into windows. otherwise all you can do is target the whole window. It really sucks but that is the way it is.

I do not know to much about chrome as i do not use it because of horrific memory leaks and crashes. But hopefully the plugin dev of that chrome browser plugin will be able to help ya.
If you like the work I have been doing then feel free to Image

cvben
Posts: 38
Joined: Wed Jun 07, 2017 8:30 pm

Re: Trying to automate Chromecast, problem controlling Chrome

Post by cvben » Thu Jan 04, 2018 1:28 am

I'm glad I saw this as it reminded me that this is a (probable) bug that has happened to me too. It seems to be an issue with clicks not properly ending. So when you right click it thinks you never stopped.

I'd use the "Apps" key instead of right clicking, like so:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-rc4">
    <Macro Name="Find Window: chrome.exe" XML_Guid="{7F5A0C02-503F-428E-84B1-0D57C20FFF0D}" Expanded="True">
        <Action XML_Guid="{29D2DB23-5968-43FA-A342-5301A4A7E056}">
            Window.FindWindow(u'chrome.exe', None, None, None, None, None, False, 0.0, 0)
        </Action>
        <Action XML_Guid="{34834336-6890-4B9D-8500-03E9732CFE34}">
            Window.BringToFront()
        </Action>
        <Action XML_Guid="{9BAD3CD1-BF02-4213-B3FD-72A47FAA25D0}">
            Mouse.MoveAbsolute(300, 300, None, False, False)
        </Action>
        <Action XML_Guid="{0DBE14B7-46AA-44B8-B117-B7262BEBD91A}">
            Window.SendKeys(u'{Apps}', False, 2)
        </Action>
        <Action XML_Guid="{22FAD725-AD8D-4F39-B6C0-F6C2DCF217CE}">
            Window.SendKeys(u'C', False, 2)
        </Action>
    </Macro>
</EventGhost>

Post Reply