OSSingleton

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.

@GodotBaseClass
struct OSSingleton {}

Members

Aliases

BaseClasses
alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses)
Undocumented in source.

Enums

Constants
enum Constants
Month
enum Month
PowerState
enum PowerState
ScreenOrientation
enum ScreenOrientation
SystemDir
enum SystemDir
Weekday
enum Weekday

Functions

alert
void alert(StringArg0 text, StringArg1 title)

Displays a modal dialog box utilizing the host OS.

canDraw
bool canDraw()

Returns true if the host OS allows drawing.

canUseThreads
bool canUseThreads()

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

centerWindow
void centerWindow()

Centers the window on the screen if in windowed mode.

closeMidiInputs
void closeMidiInputs()
delayMsec
void delayMsec(long msec)

Delay execution of the current thread by given milliseconds.

delayUsec
void delayUsec(long usec)

Delay execution of the current thread by given microseconds.

dumpMemoryToFile
void dumpMemoryToFile(StringArg0 file)

Dumps the memory allocation ringlist to a file (only works in debug). Entry format per line: "Address - Size - Description".

dumpResourcesToFile
void dumpResourcesToFile(StringArg0 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.

execute
long execute(StringArg0 path, PoolStringArray arguments, bool blocking, Array output)

Execute the file at the given path with the arguments passed as an array of strings. Platform path resolution will take place. The resolved file must exist and be executable. The arguments are used in the given order and separated by a space, so OS.execute('ping', $(D '-w', '3', 'godotengine.org'), false) will resolve to ping -w 3 godotengine.org in the system's shell. This method has slightly different behaviour based on whether the blocking mode is enabled. When blocking is enabled, the Godot thread will pause its execution while waiting for the process to terminate. The shell output of the process will be written to the output array as a single string. When the process terminates, the Godot thread will resume execution. When blocking is disabled, the Godot thread will continue while the new process runs. It is not possible to retrieve the shell output in non-blocking mode, so output will be empty. The return value also depends on the blocking mode. When blocking, the method will return -2 (no process ID information is available in blocking mode). When non-blocking, the method returns a process ID, which you can use to monitor the process (and potentially terminate it with kill). If the process forking (non-blocking) or opening (blocking) fails, the method will return -1. Example of blocking mode and retrieving the shell output:

findScancodeFromString
long findScancodeFromString(StringArg0 string)

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

getAudioDriverCount
long getAudioDriverCount()

Returns the total number of available audio drivers.

getAudioDriverName
String getAudioDriverName(long driver)

Returns the audio driver name for the given index.

getBorderlessWindow
bool getBorderlessWindow()
getClipboard
String getClipboard()
getCmdlineArgs
PoolStringArray getCmdlineArgs()

Returns the command line arguments passed to the engine.

getConnectedMidiInputs
PoolStringArray getConnectedMidiInputs()
getCurrentScreen
long getCurrentScreen()
getDate
Dictionary getDate(bool utc)

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

getDatetime
Dictionary getDatetime(bool utc)

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

getDatetimeFromUnixTime
Dictionary getDatetimeFromUnixTime(long unix_time_val)

Get a dictionary of time values when given epoch time. Dictionary Time values will be a union of values from getTime and getDate dictionaries (with the exception of dst = day light standard time, as it cannot be determined from epoch).

getDynamicMemoryUsage
long getDynamicMemoryUsage()

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

getEnvironment
String getEnvironment(StringArg0 environment)

Returns an environment variable.

getExecutablePath
String getExecutablePath()

Returns the path to the current engine executable.

getExitCode
long getExitCode()
getLatinKeyboardVariant
String getLatinKeyboardVariant()

Returns the current latin keyboard variant as a String. Possible return values are: "QWERTY", "AZERTY", "QZERTY", "DVORAK", "NEO", "COLEMAK" or "ERROR".

getLocale
String getLocale()

Returns the host OS locale.

getModelName
String getModelName()

Returns the model name of the current device.

getName
String getName()

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

getPowerPercentLeft
long getPowerPercentLeft()

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

getPowerSecondsLeft
long getPowerSecondsLeft()

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

getPowerState
OS.PowerState getPowerState()

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

getProcessId
long getProcessId()

Returns the game process ID

getProcessorCount
long getProcessorCount()

Returns the number of cores available in the host machine.

getRealWindowSize
Vector2 getRealWindowSize()

Returns the window size including decorations like window borders.

getScancodeString
String getScancodeString(long code)

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

getScreenCount
long getScreenCount()

Returns the number of displays attached to the host machine.

getScreenDpi
long getScreenDpi(long screen)

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

getScreenOrientation
OS.ScreenOrientation getScreenOrientation()
getScreenPosition
Vector2 getScreenPosition(long screen)

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

getScreenSize
Vector2 getScreenSize(long screen)

Returns the dimensions in pixels of the specified screen.

getSplashTickMsec
long getSplashTickMsec()
getStaticMemoryPeakUsage
long getStaticMemoryPeakUsage()

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

getStaticMemoryUsage
long getStaticMemoryUsage()

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

getSystemDir
String getSystemDir(long dir)

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

getSystemTimeSecs
long getSystemTimeSecs()

Returns the epoch time of the operating system in seconds.

getTicksMsec
long getTicksMsec()

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

getTicksUsec
long getTicksUsec()

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

getTime
Dictionary getTime(bool utc)

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

getTimeZoneInfo
Dictionary getTimeZoneInfo()

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

getUniqueId
String getUniqueId()

Returns a string that is unique to the device. Returns empty string on HTML5 and UWP which are not supported yet.

getUnixTime
long getUnixTime()

Returns the current unix epoch timestamp.

getUnixTimeFromDatetime
long getUnixTimeFromDatetime(Dictionary 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 directly into this function. Daylight savings time (dst), if present, is ignored.

getUserDataDir
String getUserDataDir()

Returns the absolute directory path where user data is written (user://). On Linux, this is ~/.local/share/godot/app_userdata/$(D project_name), or ~/.local/share/$(D custom_name) if use_custom_user_dir is set. On macOS, this is ~/Library/Application Support/Godot/app_userdata/$(D project_name), or ~/Library/Application Support/$(D custom_name) if use_custom_user_dir is set. On Windows, this is %APPDATA%/Godot/app_userdata/$(D project_name), or %APPDATA%/$(D custom_name) if use_custom_user_dir is set. If the project name is empty, user:// falls back to res://.

getVideoDriverCount
long getVideoDriverCount()
getVideoDriverName
String getVideoDriverName(long driver)
getVirtualKeyboardHeight
long getVirtualKeyboardHeight()

Returns the on-screen keyboard's height in pixels. Returns 0 if there is no keyboard or it is currently hidden.

getWindowPerPixelTransparencyEnabled
bool getWindowPerPixelTransparencyEnabled()
getWindowPosition
Vector2 getWindowPosition()
getWindowSafeArea
Rect2 getWindowSafeArea()
getWindowSize
Vector2 getWindowSize()
hasEnvironment
bool hasEnvironment(StringArg0 environment)

Returns true if an environment variable exists.

hasFeature
bool hasFeature(StringArg0 tag_name)

Returns true if the feature for the given feature tag is supported in the currently running instance, depending on platform, build etc. Can be used to check whether you're currently running a debug build, on a certain platform or arch, etc. See feature tags documentation.

hasTouchscreenUiHint
bool hasTouchscreenUiHint()

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

hasVirtualKeyboard
bool hasVirtualKeyboard()

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

hideVirtualKeyboard
void hideVirtualKeyboard()

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

isDebugBuild
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.

isInLowProcessorUsageMode
bool isInLowProcessorUsageMode()
isKeepScreenOn
bool isKeepScreenOn()
isOkLeftAndCancelRight
bool isOkLeftAndCancelRight()

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

isScancodeUnicode
bool isScancodeUnicode(long code)

Returns true if the input code has a unicode character.

isStdoutVerbose
bool isStdoutVerbose()

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

isUserfsPersistent
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.

isVsyncEnabled
bool isVsyncEnabled()
isWindowAlwaysOnTop
bool isWindowAlwaysOnTop()

Returns true if the window should always be on top of other windows.

isWindowFullscreen
bool isWindowFullscreen()
isWindowMaximized
bool isWindowMaximized()
isWindowMinimized
bool isWindowMinimized()
isWindowResizable
bool isWindowResizable()
kill
GodotError kill(long pid)

Kill (terminate) the process identified by the given process ID (pid), e.g. the one returned by execute in non-blocking mode. Note that this method can also be used to kill processes that were not spawned by the game.

nativeVideoIsPlaying
bool nativeVideoIsPlaying()

Returns true if native video is playing.

nativeVideoPause
void nativeVideoPause()

Pauses native video playback.

nativeVideoPlay
GodotError nativeVideoPlay(StringArg0 path, double volume, StringArg2 audio_track, StringArg3 subtitle_track)

Plays native video from the specified path, at the given volume and with audio and subtitle tracks. Note: This method is only implemented on Android and iOS, and the current Android implementation does not support the volume, audio_track and subtitle_track options.

nativeVideoStop
void nativeVideoStop()

Stops native video playback.

nativeVideoUnpause
void nativeVideoUnpause()

Resumes native video playback.

opAssign
OSSingleton opAssign(T n)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(OSSingleton other)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(typeof(null) n)
Undocumented in source. Be warned that the author may not have intended to support it.
openMidiInputs
void openMidiInputs()
printAllResources
void printAllResources(StringArg0 tofile)

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

printAllTexturesBySize
void printAllTexturesBySize()

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

printResourcesByType
void printResourcesByType(PoolStringArray types)

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

printResourcesInUse
void printResourcesInUse(bool _short)

Shows all resources currently used by the game.

requestAttention
void requestAttention()

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

setBorderlessWindow
void setBorderlessWindow(bool borderless)
setClipboard
void setClipboard(StringArg0 clipboard)
setCurrentScreen
void setCurrentScreen(long screen)
setExitCode
void setExitCode(long code)
setIcon
void setIcon(Image icon)

Sets the game's icon.

setImePosition
void setImePosition(Vector2 position)
setKeepScreenOn
void setKeepScreenOn(bool enabled)
setLowProcessorUsageMode
void setLowProcessorUsageMode(bool enable)
setScreenOrientation
void setScreenOrientation(long orientation)
setThreadName
GodotError setThreadName(StringArg0 name)

Sets the name of the current thread.

setUseFileAccessSaveAndSwap
void setUseFileAccessSaveAndSwap(bool enabled)

Enables backup saves if enabled is true.

setUseVsync
void setUseVsync(bool enable)
setWindowAlwaysOnTop
void setWindowAlwaysOnTop(bool enabled)

Sets whether the window should always be on top.

setWindowFullscreen
void setWindowFullscreen(bool enabled)
setWindowMaximized
void setWindowMaximized(bool enabled)
setWindowMinimized
void setWindowMinimized(bool enabled)
setWindowPerPixelTransparencyEnabled
void setWindowPerPixelTransparencyEnabled(bool enabled)
setWindowPosition
void setWindowPosition(Vector2 position)
setWindowResizable
void setWindowResizable(bool enabled)
setWindowSize
void setWindowSize(Vector2 size)
setWindowTitle
void setWindowTitle(StringArg0 title)

Sets the window title to the specified string.

shellOpen
GodotError shellOpen(StringArg0 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.

showVirtualKeyboard
void showVirtualKeyboard(StringArg0 existing_text)

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).

Mixins

__anonymous
mixin baseCasts
Undocumented in source.

Properties

clipboard
String clipboard [@property getter]
String clipboard [@property setter]

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

currentScreen
long currentScreen [@property getter]
long currentScreen [@property setter]

The current screen index (starting from 0).

exitCode
long exitCode [@property getter]
long exitCode [@property setter]

The exit code passed to the OS when the main loop exits.

keepScreenOn
bool keepScreenOn [@property getter]
bool keepScreenOn [@property setter]

If true the engine tries to keep the screen on while the game is running. Useful on mobile.

lowProcessorUsageMode
bool lowProcessorUsageMode [@property getter]
bool lowProcessorUsageMode [@property setter]

If true the engine optimizes for low processor usage by only refreshing the screen if needed. Can improve battery consumption on mobile.

screenOrientation
OS.ScreenOrientation screenOrientation [@property getter]
long screenOrientation [@property setter]

The current screen orientation.

vsyncEnabled
bool vsyncEnabled [@property getter]
bool vsyncEnabled [@property setter]

If true vertical synchronization (Vsync) is enabled.

windowBorderless
bool windowBorderless [@property getter]
bool windowBorderless [@property setter]

If true removes the window frame.

windowFullscreen
bool windowFullscreen [@property getter]
bool windowFullscreen [@property setter]

If true the window is fullscreen.

windowMaximized
bool windowMaximized [@property setter]

If true the window is maximized.

windowMaximized
bool windowMaximized [@property getter]

If true the window is maximized.

windowMinimized
bool windowMinimized [@property setter]

If true the window is minimized.

windowMinimized
bool windowMinimized [@property getter]

If true the window is minimized.

windowPerPixelTransparencyEnabled
bool windowPerPixelTransparencyEnabled [@property getter]
bool windowPerPixelTransparencyEnabled [@property setter]
windowPosition
Vector2 windowPosition [@property getter]
Vector2 windowPosition [@property setter]

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.

windowResizable
bool windowResizable [@property getter]
bool windowResizable [@property setter]

If true, the window is resizable by the user.

windowSize
Vector2 windowSize [@property getter]
Vector2 windowSize [@property setter]

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

Static functions

_new
OSSingleton _new()
Undocumented in source. Be warned that the author may not have intended to support it.

Static variables

_classBindingInitialized
bool _classBindingInitialized;
Undocumented in source.

Structs

_classBinding
struct _classBinding
Undocumented in source.

Unions

__anonymous
union __anonymous
Undocumented in source.

Variables

_GODOT_internal_name
enum string _GODOT_internal_name;
Undocumented in source.

Mixed In Members

From mixin baseCasts

as
To as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
To as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
ToRef as()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(ToRef)
Undocumented in source.
opCast
void* opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
godot_object opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
bool opCast()
Undocumented in source. Be warned that the author may not have intended to support it.

Meta