2

I am in need of a solution to add some kind of Shortcut to a Desktop where by the shortcut will cast the desktop to Chromecast.

I'm basically looking to simply the process for our Users as they can't seem to do ALT + F, then C or click the 3 dots.. cast etc.

I've had a Google, but can't seem to find any successful results.

I was thinking of going along the lines of creating a Batch File for this or perhaps a Macro that could quickly do it? I'm out of ideas to be honest. I know I can launch Chrome via the batch script.

2
  • Yes, but please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
    – DavidPostill
    Commented Mar 8, 2019 at 11:08
  • @DavidPostill I have edited by question.
    – ST34M
    Commented Mar 10, 2019 at 9:54

5 Answers 5

2

Make sure you have Chrome version 76.0.3809.132 or later. Install AutoHotkey. Make 2 files and place them on your desktop:

CastOn.ahk:

; AutoHotKey Script to start ChromeCast in Desktop Mode
;
; Declare variables
delay := 1000
; Run Chrome
Run, C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --fullscreen --start-maximized
Sleep, delay
Send !f
Sleep, delay
Send c
Sleep, delay
Send {tab}{tab}
Sleep, delay
Send {Enter}
Sleep, delay
Send {Down}{Down}
Sleep, delay
Send {Enter}
Sleep, delay
Send +{tab}
Send {Enter}
Sleep, delay * 2
Send {tab}
Sleep, Delay
Send {tab}
Sleep, Delay
Send {tab}
Sleep, Delay
Send {Enter}
Sleep, delay
Send #{down} ; minimize window, casting starts

CastOff.ahk:

; AutoHotKey Script to stop ChromeCast in Desktop Mode
;
; Declare variables
delay := 1000
; Run Chrome
Run, C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --fullscreen --start-maximized
Sleep, delay
Send !f
Sleep, delay
Send c
Sleep, delay
Send {tab}
Send {Enter}
Sleep, delay
Send {ESC}
Sleep, delay
Send !{f4} ; close window

Now you have 2 ahk icons on your desktop. Double clicking CastOn.ahk starts casting and leaves Chrome minimized (just wait for the magic to happen). Double clicking CastOff.ahk stops casting and closes the opened Chrome window invoked in this script.

"Sleep" is needed to avoid the simulated keystrokes to launch to early, you can however experiment with the delay variable (now set to 1000 ms, one second).

Newer versions of Chrome may lead to new UI changes in the ChromeCast functionality, which would mean this script needs to be adjusted.

Chrome may be installed in a different path as mentioned in the ahk scripts. It would not be too difficult to sort out the correct location of Chrome.exe.

0

So, I have a partial solution, and as of know, it's the only solution I know of. The only part I couldn't figure out was how to switch from casting tab to casting desktop. But, here's a nifty powershell script that you can use.

PowerShell.exe -windowstyle hidden { 
    if (Test-Path variable:global:wshell) {
        Clear-Variable wshell -Scope Global } 
    $wshell = New-Object -ComObject wscript.shell; 
    if (!$wshell.AppActivate("chrome")){
        ."\Program Files (x86)\Google\Chrome\Application\chrome.exe"
        Sleep 1
    }
    $wshell.AppActivate("chrome")
    Sleep .5
    $wshell.SendKeys('%(f)')
    Sleep .5
    $wshell.SendKeys('c')
    exit
}

And if you save this as a ps1 file (such as chromecast.ps1) in your documents, you can create a shortcut on the desktop that points to this file. (You can then go into the properties of the shortcut and change the icon if you'd like).

0

This AutoHotkey solution is nice...

I'm not sure if the interface HAS changed.. but this does not currently work for me.

It opens chrome.. opens the cast tab... but there is no way to seclect the SOURCE as desktop from the drop down source list.. and there is no way to select a specific casting device if you have more than one.

If you could provide the code snipit to select the drop down box.. and select a specific selection .. either by selection id or name.. that would be great.. I could then try to bastardize the code to make it select the SOURCE and DESTINATION properly.

0

Ok.. so i figured out that the interface selection is dependent upon how many chromecast devices you have. SO i put together a AutoHotkey variation of Marcel Pennock's code...

This allows you to define how many times the script needs to hit the TAB button... to select the proper casting device from the populated list crhome gives you of detected devices.

So.. if you want to cast to device 2 on your list.. you set the deviceNumber parameter to be the number of the device in the list ( 1 = first device listed.. 2 = second.. etc ).

Also.. I made it so you can select what casting mode you want... be default I set it to DESKTOP ( option 2 ).

Again.. its all about how many times you need to hit TAB to select what you want...

CastOn-1.ahk:

;------------------------------------------------------------
; AutoHotKey Script to START ChromeCast in Desktop Mode
;
; Declare variables
;
; -- Set CastMode (1=TAB 2=DESKTOP 3=FILE)
castMode := 2
deviceNumber := 1
;
delay := 1000
;------------------------------------------------------------


;------------------------------------------------------------
; Run Chrome
Run, C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --fullscreen --start-maximized

;Sleep, delay
Sleep, 5000

#IfWinActive, ahk_class Chrome_WidgetWin_1

; -- SEND the ALT+F key combo to open settings
SendInput !f
Sleep, delay

; -- SEND the C key combo to select CAST
SendInput c
Sleep, delay
;------------------------------------------------------------

;------------------------------------------------------------
; -- Tab to the SOURCES drop down box and select it.
SendInput {TAB 3}
Sleep, delay

SendInput {Enter}
Sleep, delay
;------------------------------------------------------------

;------------------------------------------------------------
; -- Make your Selection ( One DOWN for TAB, Two DOWN for DESKTOP, THREE down for FILE.)
; Select DESKTOP -- TWO DOWN COMMANDS PASSED
SendInput {Down %castMode%}
Sleep, delay

SendInput {Enter}
Sleep, delay
;------------------------------------------------------------

;------------------------------------------------------------
; -- Tab  OUT of the Source Selection area ..   to be able to select correct device.
SendInput {TAB}
Sleep, delay

; -- Tab to the DEVICE we selected and 
SendInput {TAB %deviceNumber%}
Sleep, delay

; -- START CAST. 
SendInput {Enter}
Sleep, delay
;------------------------------------------------------------

;------------------------------------------------------------
; -- Minimize window, casting starts
Send {ESC}
Sleep, delay
Send #{d} ; minimize window, casting starts
;------------------------------------------------------------

CastOff-1.ahk:

;------------------------------------------------------------
; AutoHotKey Script to STOP ChromeCast in Desktop Mode
;
; Declare variables
delay := 1000
;------------------------------------------------------------


;------------------------------------------------------------
; Run Chrome
Run, C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --fullscreen --start-maximized

;Sleep, delay
Sleep, 5000

#IfWinActive, ahk_class Chrome_WidgetWin_1

; -- SEND the ALT+F key combo to open settings
SendInput !f
Sleep, delay

; -- SEND the C key combo to select CAST
SendInput c
Sleep, delay
;------------------------------------------------------------


;------------------------------------------------------------
; -- Tab  OUT of the Source Selection area ..   to be able to select correct device.
SendInput {TAB}
Sleep, delay

; -- Tab to the DEVICE we selected and 
SendInput {TAB %deviceNumber%}
Sleep, delay

; -- STOP CAST. 
SendInput {Enter}
Sleep, delay
;------------------------------------------------------------

;------------------------------------------------------------
; -- CLOSE window
Send {ESC}
Sleep, delay

Send !{f4} ; close window
;------------------------------------------------------------

I also launch this directly from within a batch file... so i can call the batch file from ANY program.. it comes in handy for applications that allow you to map key or an event into a function or activity.

Example: I have StreamDeck device i use when streaming video.. i can simply map one of the streamdeck buttons.. to launch this batch file.. and bam.. one button press on the device.. and i'm autocasting to my chromecast device as well.

[SCRIPT LOCATION] refers to your local script path obviously replace this.

START_AUTOHOTKEYCHROMECAST.bat

@echo off
cd "C:\Program Files\AutoHotkey" && start "CHROMECAST START" "C:\Program Files\AutoHotkey\AutoHotkey.exe" "[SCRIPT LOCATION]\CastON.ahk"
exit
0

If you have more than one chromecast device, here's a powershell script that tabs between them to select the correct one.

PowerShell.exe -windowstyle hidden {
    $wshell = New-Object -ComObject wscript.shell;
    Start-Process "chrome.exe"
    Sleep 5
    # Open Chromes menu and select cast
    $wshell.SendKeys('%(f)c')
    Sleep 1
    # Tab down do the sources button (alter the number of tabs based on how many chromecast devices you have)
    $wshell.SendKeys('{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}')
    Sleep 1
    # Select cast to desktop
    $wshell.SendKeys('{DOWN}{DOWN}{ENTER}')
    Sleep 1
    # Tab back up and select the correct chromecast device to use (alter number of shift tabs)
    $wshell.SendKeys('+{TAB}{ENTER}')
    exit
}

Save it as as something like StartChromecast.ps1.

Then to run it:

powershell.exe -executionpolicy bypass -File StartChromecast.ps1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .