Operating System functions.
    public static class OS

Operating System functions. OS Wraps the most common functionality to communicate with the host Operating System, such as: mouse grabbing, mouse cursors, clipboard, video mode, date and time, timers, environment variables, execution of binaries, command line, etc.

Inheritance Chain

Static Properties

    public static string Clipboard { get; set; }

The clipboard from the host OS. Might be unavailable on some platforms.

    public static int CurrentScreen { get; set; }

The current screen index (starting from 0).

    public static int ExitCode { get; set; }

    public static bool KeepScreenOn { get; set; }

    public static bool LowProcessorUsageMode { get; set; }

    public static ScreenOrientationEnum ScreenOrientation { get; set; }

The current screen orientation.

    public static bool VsyncEnabled { get; set; }

    public static bool WindowBorderless { get; set; }

If true, removes the window frame.

    public static bool WindowFullscreen { get; set; }

If true, the window is fullscreen.

    public static bool WindowMaximized { get; set; }

If true, the window is maximized.

    public static bool WindowMinimized { get; set; }

If true, the window is minimized.

    public static Vector2 WindowPosition { get; set; }

The window position relative to the screen, the origin is the top left corner, +Y axis goes to the bottom and +X axis goes to the right.

    public static bool WindowResizable { get; set; }

If true, the window is resizable by the user.

    public static Vector2 WindowSize { get; set; }

The size of the window (without counting window manager decorations).

Static Methods

    public static void Alert(string text, string title = "Alert!")

Displays a modal dialog box utilizing the host OS.

    public static bool CanDraw()

Returns true if the host OS allows drawing.

    public static bool CanUseThreads()

Returns true if the current host platform is using multiple threads.

    public static void DelayMsec(int msec)

Delay executing of the current thread by given milliseconds.

    public static void DelayUsec(int usec)

Delay executing of the current thread by given microseconds.

    public static void DumpMemoryToFile(string file)

Dumps the memory allocation ringlist to a file (only works in debug).

Entry format per line: “Address - Size - Description”

    public static void DumpResourcesToFile(string file)

Dumps all used resources to file (only works in debug).

Entry format per line: “Resource Type : Resource Location”

At the end of the file is a statistic of all used Resource Types.

    public static int Execute(string path, string[] arguments, bool blocking, object[] output = null)

Execute the file at the given path, optionally blocking until it returns.

Platform path resolution will take place. The resolved file must exist and be executable.

Returns a process id.

For example:


var output = []

var pid = OS.execute(‘ls’, [], true, output)


If you wish to access a shell built-in or perform a composite command, a platform specific shell can be invoked. For example:


var pid = OS.execute(‘CMD.exe’, [‘/C’, ‘cd %TEMP% && dir’], true, output)


    public static int FindScancodeFromString(string @string)

Returns the scancode of the given string (e.g. “Escape”)

    public static bool GetBorderlessWindow()

Getter for WindowBorderless

    public static string GetClipboard()

Getter for Clipboard

    public static string[] GetCmdlineArgs()

Returns the command line arguments passed to the engine.

    public static int GetCurrentScreen()

Getter for CurrentScreen

    public static Dictionary<object, object> GetDate(bool utc = false)

Returns current date as a dictionary of keys: year, month, day, weekday, dst (daylight savings time).

    public static Dictionary<object, object> GetDatetime(bool utc = false)

Returns current datetime as a dictionary of keys: year, month, day, weekday, dst (daylight savings time), hour, minute, second.

    public static Dictionary<object, object> GetDatetimeFromUnixTime(int unixTimeVal)

Get a dictionary of time values when given epoch time.

Dictionary Time values will be a union of values from GetTime(bool) and GetDate(bool) dictionaries (with the exception of dst = day light standard time, as it cannot be determined from epoch).

    public static int GetDynamicMemoryUsage()

Returns the total amount of dynamic memory used (only works in debug).

    public static string GetEnvironment(string environment)

Returns an environment variable.

    public static string GetExecutablePath()

Returns the path to the current engine executable.

    public static int GetExitCode()

Getter for ExitCode

    public static string GetLatinKeyboardVariant()

Returns the current latin keyboard variant as a String.

Possible return values are: “QWERTY”, “AZERTY”, “QZERTY”, “DVORAK”, “NEO”, “COLEMAK” or “ERROR”.

    public static string GetLocale()

Returns the host OS locale.

    public static string GetModelName()

Returns the model name of the current device.

    public static string GetName()

Returns the name of the host OS. Possible values are: “Android”, “Haiku”, “iOS”, “HTML5”, “OSX”, “Server”, “Windows”, “UWP”, “X11”.

    public static int GetPowerPercentLeft()

Returns the amount of battery left in the device as a percentage.

    public static int GetPowerSecondsLeft()

Returns the time in seconds before the device runs out of battery.

    public static PowerState GetPowerState()

Returns the current state of the device regarding battery and power. See POWERSTATE_* constants.

    public static int GetProcessId()

Returns the game process ID

    public static int GetProcessorCount()

Returns the number of cores available in the host machine.

    public static string GetScancodeString(int code)

Returns the given scancode as a string (e.g. Return values: “Escape”, “Shift+Escape”).

    public static int GetScreenCount()

Returns the number of displays attached to the host machine.

    public static int GetScreenDpi(int screen = -1)

Returns the dots per inch density of the specified screen.

On Android Devices, the actual screen densities are grouped into six generalized densities:

ldpi - 120 dpi

mdpi - 160 dpi

hdpi - 240 dpi

xhdpi - 320 dpi

xxhdpi - 480 dpi

xxxhdpi - 640 dpi

    public static ScreenOrientationEnum GetScreenOrientation()

Getter for ScreenOrientation

    public static Vector2 GetScreenPosition(int screen = -1)

Returns the position of the specified screen by index. If no screen index is provided, the current screen will be used.

    public static Vector2 GetScreenSize(int screen = -1)

Returns the dimensions in pixels of the specified screen.

    public static int GetSplashTickMsec()

    public static int GetStaticMemoryPeakUsage()

Returns the max amount of static memory used (only works in debug).

    public static int GetStaticMemoryUsage()

Returns the amount of static memory being used by the program in bytes.

    public static string GetSystemDir(SystemDir dir)

Returns the actual path to commonly used folders across different platforms. Available locations are specified in OS.SystemDir.

    public static int GetSystemTimeSecs()

Returns the epoch time of the operating system in seconds.

    public static int GetTicksMsec()

Returns the amount of time passed in milliseconds since the engine started.

    public static Dictionary<object, object> GetTime(bool utc = false)

Returns current time as a dictionary of keys: hour, minute, second.

    public static Dictionary<object, object> GetTimeZoneInfo()

Returns the current time zone as a dictionary with the keys: bias and name.

    public static string GetUniqueId()

Returns a string that is unique to the device. Currently only works on Android and iOS. Returns empty string on other platforms.

    public static int GetUnixTime()

Return the current unix timestamp.

    public static int GetUnixTimeFromDatetime(Dictionary<object, object> datetime)

Get an epoch time value from a dictionary of time values.

datetime must be populated with the following keys: year, month, day, hour, minute, second.

You can pass the output from GetDatetimeFromUnixTime(int) directly into this function. Daylight savings time (dst), if present, is ignored.

    public static string GetUserDataDir()

Returns the absolute directory path where user data is written (user://).

    public static int GetVirtualKeyboardHeight()

    public static Vector2 GetWindowPosition()

Getter for WindowPosition

    public static Vector2 GetWindowSize()

Getter for WindowSize

    public static bool HasEnvironment(string environment)

Returns true if an environment variable exists.

    public static bool HasFeature(string tagName)

    public static bool HasTouchscreenUiHint()

Returns true if the device has a touchscreen or emulates one.

    public static bool HasVirtualKeyboard()

Returns true if the platform has a virtual keyboard, false otherwise.

    public static void HideVirtualKeyboard()

Hides the virtual keyboard if it is shown, does nothing otherwise.

    public static bool IsDebugBuild()

Returns true if the build is a debug build.

Returns true when running in the editor.

Returns false if the build is a release build.

    public static bool IsInLowProcessorUsageMode()

Getter for LowProcessorUsageMode

    public static bool IsKeepScreenOn()

Getter for KeepScreenOn

    public static bool IsOkLeftAndCancelRight()

Returns true if the “Okay” button should appear on the left and “Cancel” on the right.

    public static bool IsScancodeUnicode(int code)

Returns true if the input code has a unicode character.

    public static bool IsStdoutVerbose()

Returns true if the engine was executed with -v (verbose stdout).

    public static bool IsUserfsPersistent()

If true, the user:// file system is persistent, so that its state is the same after a player quits and starts the game again. Relevant to the HTML5 platform, where this persistence may be unavailable.

    public static bool IsVsyncEnabled()

Getter for VsyncEnabled

    public static bool IsWindowFullscreen()

Getter for WindowFullscreen

    public static bool IsWindowMaximized()

Getter for WindowMaximized

    public static bool IsWindowMinimized()

Getter for WindowMinimized

    public static bool IsWindowResizable()

Getter for WindowResizable

    public static Error Kill(int pid)

Kill a process ID (this method can be used to kill processes that were not spawned by the game).

    public static bool NativeVideoIsPlaying()

Returns true if native video is playing.

    public static void NativeVideoPause()

Pauses native video playback.

    public static Error NativeVideoPlay(string path, float volume, string audioTrack, string subtitleTrack)

Plays native video from the specified path, at the given volume and with audio and subtitle tracks.

    public static void NativeVideoStop()

Stops native video playback.

    public static void NativeVideoUnpause()

Resumes native video playback.

    public static void PrintAllResources(string tofile = "")

Shows all resources in the game. Optionally the list can be written to a file.

    public static void PrintAllTexturesBySize()

Shows the list of loaded textures sorted by size in memory.

    public static void PrintResourcesByType(string[] types)

Shows the number of resources loaded by the game of the given types.

    public static void PrintResourcesInUse(bool @short = false)

Shows all resources currently used by the game.

    public static void RequestAttention()

Request the user attention to the window. It’ll flash the taskbar button on Windows or bounce the dock icon on OSX.

    public static void SetBorderlessWindow(bool borderless)

Setter for WindowBorderless

    public static void SetClipboard(string clipboard)

Setter for Clipboard

    public static void SetCurrentScreen(int screen)

Setter for CurrentScreen

    public static void SetExitCode(int code)

Setter for ExitCode

    public static void SetIcon(Image icon)

Sets the game’s icon.

    public static void SetImePosition(Vector2 position)

    public static void SetKeepScreenOn(bool enabled)

Setter for KeepScreenOn

    public static void SetLowProcessorUsageMode(bool enable)

Setter for LowProcessorUsageMode

    public static void SetScreenOrientation(ScreenOrientationEnum orientation)

Setter for ScreenOrientation

    public static Error SetThreadName(string name)

Sets the name of the current thread.

    public static void SetUseFileAccessSaveAndSwap(bool enabled)

Enables backup saves if enabled is true.

    public static void SetUseVsync(bool enable)

Setter for VsyncEnabled

    public static void SetWindowFullscreen(bool enabled)

Setter for WindowFullscreen

    public static void SetWindowMaximized(bool enabled)

Setter for WindowMaximized

    public static void SetWindowMinimized(bool enabled)

Setter for WindowMinimized

    public static void SetWindowPosition(Vector2 position)

Setter for WindowPosition

    public static void SetWindowResizable(bool enabled)

Setter for WindowResizable

    public static void SetWindowSize(Vector2 size)

Setter for WindowSize

    public static void SetWindowTitle(string title)

Sets the window title to the specified string.

    public static Error ShellOpen(string uri)

Requests the OS to open a resource with the most appropriate program. For example.

OS.shell_open("C:\\Users\name\Downloads") on Windows opens the file explorer at the downloads folders of the user.

OS.shell_open("http://godotengine.org") opens the default web browser on the official Godot website.

    public static void ShowVirtualKeyboard(string existingText = "")

Shows the virtual keyboard if the platform has one. The existing_text parameter is useful for implementing your own LineEdit, as it tells the virtual keyboard what text has already been typed (the virtual keyboard uses it for auto-correct and predictions).

Inner Types


Name Value Description
January 1  
February 2  
March 3  
April 4  
May 5  
June 6  
July 7  
August 8  
September 9  
October 10  
November 11  
December 12  


Name Value Description
Unknown 0  
OnBattery 1  
NoBattery 2  
Charging 3  
Charged 4  


Name Value Description
Landscape 0  
Portrait 1  
ReverseLandscape 2  
ReversePortrait 3  
SensorLandscape 4  
SensorPortrait 5  
Sensor 6  


Name Value Description
Desktop 0  
Dcim 1  
Documents 2  
Downloads 3  
Movies 4  
Music 5  
Pictures 6  
Ringtones 7  


Name Value Description
Sunday 0  
Monday 1  
Tuesday 2  
Wednesday 3  
Thursday 4  
Friday 5  
Saturday 6