Skip to content

Instantly share code, notes, and snippets.

@SuperIzzo
Last active July 16, 2017 11:32
Show Gist options
  • Save SuperIzzo/51bce5f3da486b6c9ac65bf653e861b0 to your computer and use it in GitHub Desktop.
Save SuperIzzo/51bce5f3da486b6c9ac65bf653e861b0 to your computer and use it in GitHub Desktop.
A quick and dirty hack to run chrome in Fullscreen (Kiosk) mode
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace ChromeKioskRunner
{
class Program
{
private const uint WM_KEYDOWN = 0x100;
private const int VK_F11 = 0x7A;
[DllImport( "user32.dll" )]
static extern IntPtr GetForegroundWindow();
[DllImport( "user32.dll" )]
private static extern IntPtr SendMessage( IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam );
[DllImport( "user32.dll" )]
[return: MarshalAs( UnmanagedType.Bool )]
static extern bool IsWindow( IntPtr hWnd );
static void Main( string[] args )
{
string program = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
string defaultOptions = @"--new-window ";
string combinedArgs = defaultOptions + string.Join( " ", args );
var process = Process.Start( program, combinedArgs );
// Wait and get the foreground window
// hopefully nothing interups the process start...
System.Threading.Thread.Sleep( 500 );
IntPtr activeWindowHandle = GetForegroundWindow();
// Send F11 keystroke (i.e. fullscreen hotkey)
SendMessage( activeWindowHandle,
WM_KEYDOWN,
new IntPtr( VK_F11 ),
new IntPtr( 0x0 ) );
// Wait for the window to close before returning
while( IsWindow( activeWindowHandle ) )
{
System.Threading.Thread.Sleep( 1000 );
}
}
}
}
@SuperIzzo
Copy link
Author

SuperIzzo commented Jul 16, 2017

Needed that to start Netflix and Crunchyroll from Steam Big Picture (since --kiosk is officially deprecated in chrome).
Feel free to do whatever you want with it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment