Last active
July 16, 2017 11:32
-
-
Save SuperIzzo/51bce5f3da486b6c9ac65bf653e861b0 to your computer and use it in GitHub Desktop.
A quick and dirty hack to run chrome in Fullscreen (Kiosk) mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 :)