OS

Inherits: Object

Category: Core

Brief Description

Operating System functions.

Properties

Stringclipboard
intcurrent_screen
intexit_code
boolkeep_screen_on
boollow_processor_usage_mode
_OS.ScreenOrientationscreen_orientation
boolvsync_enabled
boolwindow_borderless
boolwindow_fullscreen
boolwindow_maximized
boolwindow_minimized
boolwindow_per_pixel_transparency_enabled
Vector2window_position
boolwindow_resizable
Vector2window_size

Methods

voidalert ( String text, String title=”Alert!” )
boolcan_draw ( ) const
boolcan_use_threads ( ) const
voidcenter_window ( )
voidclose_midi_inputs ( )
voiddelay_msec ( int msec ) const
voiddelay_usec ( int usec ) const
voiddump_memory_to_file ( String file )
voiddump_resources_to_file ( String file )
intexecute ( String path, PoolStringArray arguments, bool blocking, Array output=[ ] )
intfind_scancode_from_string ( String string ) const
intget_audio_driver_count ( ) const
Stringget_audio_driver_name ( int driver ) const
PoolStringArrayget_cmdline_args ( )
PoolStringArrayget_connected_midi_inputs ( )
VideoDriverget_current_video_driver ( ) const
Dictionaryget_date ( bool utc=false ) const
Dictionaryget_datetime ( bool utc=false ) const
Dictionaryget_datetime_from_unix_time ( int unix_time_val ) const
intget_dynamic_memory_usage ( ) const
Stringget_environment ( String environment ) const
Stringget_executable_path ( ) const
Vector2get_ime_selection ( ) const
Stringget_ime_text ( ) const
Stringget_latin_keyboard_variant ( ) const
Stringget_locale ( ) const
Stringget_model_name ( ) const
Stringget_name ( ) const
intget_power_percent_left ( )
intget_power_seconds_left ( )
PowerStateget_power_state ( )
intget_process_id ( ) const
intget_processor_count ( ) const
Vector2get_real_window_size ( ) const
Stringget_scancode_string ( int code ) const
intget_screen_count ( ) const
intget_screen_dpi ( int screen=-1 ) const
Vector2get_screen_position ( int screen=-1 ) const
Vector2get_screen_size ( int screen=-1 ) const
intget_splash_tick_msec ( ) const
intget_static_memory_peak_usage ( ) const
intget_static_memory_usage ( ) const
Stringget_system_dir ( SystemDir dir ) const
intget_system_time_msecs ( ) const
intget_system_time_secs ( ) const
intget_ticks_msec ( ) const
intget_ticks_usec ( ) const
Dictionaryget_time ( bool utc=false ) const
Dictionaryget_time_zone_info ( ) const
Stringget_unique_id ( ) const
intget_unix_time ( ) const
intget_unix_time_from_datetime ( Dictionary datetime ) const
Stringget_user_data_dir ( ) const
intget_video_driver_count ( ) const
Stringget_video_driver_name ( VideoDriver driver ) const
intget_virtual_keyboard_height ( )
Rect2get_window_safe_area ( ) const
boolhas_environment ( String environment ) const
boolhas_feature ( String tag_name ) const
boolhas_touchscreen_ui_hint ( ) const
boolhas_virtual_keyboard ( ) const
voidhide_virtual_keyboard ( )
boolis_debug_build ( ) const
boolis_ok_left_and_cancel_right ( ) const
boolis_scancode_unicode ( int code ) const
boolis_stdout_verbose ( ) const
boolis_userfs_persistent ( ) const
boolis_window_always_on_top ( ) const
Errorkill ( int pid )
voidmove_window_to_foreground ( )
boolnative_video_is_playing ( )
voidnative_video_pause ( )
Errornative_video_play ( String path, float volume, String audio_track, String subtitle_track )
voidnative_video_stop ( )
voidnative_video_unpause ( )
voidopen_midi_inputs ( )
voidprint_all_resources ( String tofile=”” )
voidprint_all_textures_by_size ( )
voidprint_resources_by_type ( PoolStringArray types )
voidprint_resources_in_use ( bool short=false )
voidrequest_attention ( )
boolrequest_permission ( String name )
voidset_icon ( Image icon )
voidset_ime_active ( bool active )
voidset_ime_position ( Vector2 position )
Errorset_thread_name ( String name )
voidset_use_file_access_save_and_swap ( bool enabled )
voidset_window_always_on_top ( bool enabled )
voidset_window_title ( String title )
Errorshell_open ( String uri )
voidshow_virtual_keyboard ( String existing_text=”” )

Enumerations

enum VideoDriver:

  • VIDEO_DRIVER_GLES2 = 1 — The GLES2 rendering backend. It uses OpenGL ES 2.0 on mobile devices, OpenGL 2.1 on desktop platforms and WebGL 1.0 on the web.
  • VIDEO_DRIVER_GLES3 = 0 — The GLES3 rendering backend. It uses OpenGL ES 3.0 on mobile devices, OpenGL 3.3 on desktop platforms and WebGL 2.0 on the web.

enum Weekday:

  • DAY_SUNDAY = 0 — Sunday.
  • DAY_MONDAY = 1 — Monday.
  • DAY_TUESDAY = 2 — Tuesday.
  • DAY_WEDNESDAY = 3 — Wednesday.
  • DAY_THURSDAY = 4 — Thursday.
  • DAY_FRIDAY = 5 — Friday.
  • DAY_SATURDAY = 6 — Saturday.

enum Month:

  • MONTH_JANUARY = 1 — January.
  • MONTH_FEBRUARY = 2 — February.
  • MONTH_MARCH = 3 — March.
  • MONTH_APRIL = 4 — April.
  • MONTH_MAY = 5 — May.
  • MONTH_JUNE = 6 — June.
  • MONTH_JULY = 7 — July.
  • MONTH_AUGUST = 8 — August.
  • MONTH_SEPTEMBER = 9 — September.
  • MONTH_OCTOBER = 10 — October.
  • MONTH_NOVEMBER = 11 — November.
  • MONTH_DECEMBER = 12 — December.

enum ScreenOrientation:

  • SCREEN_ORIENTATION_LANDSCAPE = 0 — Landscape screen orientation.
  • SCREEN_ORIENTATION_PORTRAIT = 1 — Portrait screen orientation.
  • SCREEN_ORIENTATION_REVERSE_LANDSCAPE = 2 — Reverse landscape screen orientation.
  • SCREEN_ORIENTATION_REVERSE_PORTRAIT = 3 — Reverse portrait screen orientation.
  • SCREEN_ORIENTATION_SENSOR_LANDSCAPE = 4 — Uses landscape or reverse landscape based on the hardware sensor.
  • SCREEN_ORIENTATION_SENSOR_PORTRAIT = 5 — Uses portrait or reverse portrait based on the hardware sensor.
  • SCREEN_ORIENTATION_SENSOR = 6 — Uses most suitable orientation based on the hardware sensor.

enum SystemDir:

  • SYSTEM_DIR_DESKTOP = 0 — Desktop directory path.
  • SYSTEM_DIR_DCIM = 1 — DCIM (Digital Camera Images) directory path.
  • SYSTEM_DIR_DOCUMENTS = 2 — Documents directory path.
  • SYSTEM_DIR_DOWNLOADS = 3 — Downloads directory path.
  • SYSTEM_DIR_MOVIES = 4 — Movies directory path.
  • SYSTEM_DIR_MUSIC = 5 — Music directory path.
  • SYSTEM_DIR_PICTURES = 6 — Pictures directory path.
  • SYSTEM_DIR_RINGTONES = 7 — Ringtones directory path.

enum PowerState:

  • POWERSTATE_UNKNOWN = 0 — Unknown powerstate.
  • POWERSTATE_ON_BATTERY = 1 — Unplugged, running on battery.
  • POWERSTATE_NO_BATTERY = 2 — Plugged in, no battery available.
  • POWERSTATE_CHARGING = 3 — Plugged in, battery charging.
  • POWERSTATE_CHARGED = 4 — Plugged in, battery fully charged.

Description

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

Property Descriptions

Setterset_clipboard(value)
Getterget_clipboard()

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


  • int current_screen
Setterset_current_screen(value)
Getterget_current_screen()

The current screen index (starting from 0).


Setterset_exit_code(value)
Getterget_exit_code()

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


  • bool keep_screen_on
Setterset_keep_screen_on(value)
Getteris_keep_screen_on()

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


  • bool low_processor_usage_mode
Setterset_low_processor_usage_mode(value)
Getteris_in_low_processor_usage_mode()

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


  • _OS.ScreenOrientation screen_orientation
Setterset_screen_orientation(value)
Getterget_screen_orientation()

The current screen orientation.


Setterset_use_vsync(value)
Getteris_vsync_enabled()

If true, vertical synchronization (Vsync) is enabled.


  • bool window_borderless
Setterset_borderless_window(value)
Getterget_borderless_window()

If true, removes the window frame.


  • bool window_fullscreen
Setterset_window_fullscreen(value)
Getteris_window_fullscreen()

If true, the window is fullscreen.


  • bool window_maximized
Setterset_window_maximized(value)
Getteris_window_maximized()

If true, the window is maximized.


  • bool window_minimized
Setterset_window_minimized(value)
Getteris_window_minimized()

If true, the window is minimized.


  • bool window_per_pixel_transparency_enabled
Setterset_window_per_pixel_transparency_enabled(value)
Getterget_window_per_pixel_transparency_enabled()

Setterset_window_position(value)
Getterget_window_position()

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.


  • bool window_resizable
Setterset_window_resizable(value)
Getteris_window_resizable()

If true, the window is resizable by the user.


Setterset_window_size(value)
Getterget_window_size()

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

Method Descriptions

Displays a modal dialog box utilizing the host OS.


  • bool can_draw ( ) const

Returns true if the host OS allows drawing.


  • bool can_use_threads ( ) const

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


  • void center_window ( )

Centers the window on the screen if in windowed mode.


  • void close_midi_inputs ( )

  • void delay_msec ( int msec ) const

Delay execution of the current thread by given milliseconds.


  • void delay_usec ( int usec ) const

Delay execution of the current thread by given microseconds.


  • void dump_memory_to_file ( String file )

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

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


  • void dump_resources_to_file ( 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.


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', ['-w', '3', 'godotengine.org'], false) will resolve to ping -w 3 godotengine.org in the system’s shell.

This method has slightly different behavior 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:

  1. var output = []
  2. OS.execute('ls', ['-l', '/tmp'], true, output)

Example of non-blocking mode, running another instance of the project and storing its process ID:

  1. var pid = OS.execute(OS.get_executable_path(), [], false)

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

  1. OS.execute('CMD.exe', ['/C', 'cd %TEMP% && dir'], true, output)

  • int find_scancode_from_string ( String string ) const

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


  • int get_audio_driver_count ( ) const

Returns the total number of available audio drivers.


  • String get_audio_driver_name ( int driver ) const

Returns the audio driver name for the given index.


Returns the command line arguments passed to the engine.



Returns the currently used video driver, using one of the values from VideoDriver.


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


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


  • Dictionary get_datetime_from_unix_time ( int unix_time_val ) const

Get a dictionary of time values when given epoch time.

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


  • int get_dynamic_memory_usage ( ) const

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


Returns an environment variable.


  • String get_executable_path ( ) const

Returns the path to the current engine executable.


  • Vector2 get_ime_selection ( ) const

Returns IME cursor position (currently edited portion of the string) relative to the characters in the composition string.

MainLoop.NOTIFICATION_OS_IME_UPDATE is sent to the application to notify it of changes to the IME cursor position.


  • String get_ime_text ( ) const

Returns IME intermediate composition string.

MainLoop.NOTIFICATION_OS_IME_UPDATE is sent to the application to notify it of changes to the IME composition string.


  • String get_latin_keyboard_variant ( ) const

Returns the current latin keyboard variant as a String.

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


Returns the host OS locale.


  • String get_model_name ( ) const

Returns the model name of the current device.


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


  • int get_power_percent_left ( )

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


  • int get_power_seconds_left ( )

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


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


  • int get_process_id ( ) const

Returns the game process ID


  • int get_processor_count ( ) const

Returns the number of cores available in the host machine.


  • Vector2 get_real_window_size ( ) const

Returns the window size including decorations like window borders.


  • String get_scancode_string ( int code ) const

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


  • int get_screen_count ( ) const

Returns the number of displays attached to the host machine.


  • int get_screen_dpi ( int screen=-1 ) const

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


  • Vector2 get_screen_position ( int screen=-1 ) const

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


Returns the dimensions in pixels of the specified screen.


  • int get_splash_tick_msec ( ) const

Returns the amount of time in milliseconds it took for the boot logo to appear.


  • int get_static_memory_peak_usage ( ) const

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


  • int get_static_memory_usage ( ) const

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


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


  • int get_system_time_msecs ( ) const

Returns the epoch time of the operating system in milliseconds.


  • int get_system_time_secs ( ) const

Returns the epoch time of the operating system in seconds.


  • int get_ticks_msec ( ) const

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


  • int get_ticks_usec ( ) const

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


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


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


  • String get_unique_id ( ) const

Returns a string that is unique to the device.

Returns empty string on HTML5 and UWP which are not supported yet.


  • int get_unix_time ( ) const

Returns the current unix epoch timestamp.


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


  • String get_user_data_dir ( ) const

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

On Linux, this is ~/.local/share/godot/app_userdata/[project_name], or ~/.local/share/[custom_name] if use_custom_user_dir is set.

On macOS, this is ~/Library/Application Support/Godot/app_userdata/[project_name], or ~/Library/Application Support/[custom_name] if use_custom_user_dir is set.

On Windows, this is %APPDATA%\Godot\app_userdata\[project_name], or %APPDATA%\[custom_name] if use_custom_user_dir is set. %APPDATA% expands to %USERPROFILE%\AppData\Roaming.

If the project name is empty, user:// falls back to res://.


  • int get_video_driver_count ( ) const

Returns the number of video drivers supported on the current platform.


Returns the name of the video driver matching the given driver index. This index is a value from VideoDriver, and you can use get_current_video_driver to get the current backend’s index.


  • int get_virtual_keyboard_height ( )

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


  • Rect2 get_window_safe_area ( ) const

Returns unobscured area of the window where interactive controls should be rendered.


  • bool has_environment ( String environment ) const

Returns true if an environment variable exists.


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. Refer to the Feature Tags documentation for more details.

Note that tag names are case-sensitive.


  • bool has_touchscreen_ui_hint ( ) const

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


  • bool has_virtual_keyboard ( ) const

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


  • void hide_virtual_keyboard ( )

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


  • bool is_debug_build ( ) const

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.


  • bool is_ok_left_and_cancel_right ( ) const

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


  • bool is_scancode_unicode ( int code ) const

Returns true if the input code has a unicode character.


  • bool is_stdout_verbose ( ) const

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


  • bool is_userfs_persistent ( ) const

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.


  • bool is_window_always_on_top ( ) const

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


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.


  • void move_window_to_foreground ( )

Moves the window to the front.


  • bool native_video_is_playing ( )

Returns true if native video is playing.


  • void native_video_pause ( )

Pauses native video playback.


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.


  • void native_video_stop ( )

Stops native video playback.


  • void native_video_unpause ( )

Resumes native video playback.


  • void open_midi_inputs ( )

  • void print_all_resources ( String tofile=”” )

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


  • void print_all_textures_by_size ( )

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


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


  • void print_resources_in_use ( bool short=false )

Shows all resources currently used by the game.


  • void request_attention ( )

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


At the moment this function is only used by AudioDriverOpenSL to request permission for RECORD_AUDIO on Android.


  • void set_icon ( Image icon )

Sets the game’s icon.


  • void set_ime_active ( bool active )

Sets whether IME input mode should be enabled.


  • void set_ime_position ( Vector2 position )

Sets position of IME suggestion list popup (in window coordinates).


Sets the name of the current thread.


  • void set_use_file_access_save_and_swap ( bool enabled )

Enables backup saves if enabled is true.


  • void set_window_always_on_top ( bool enabled )

Sets whether the window should always be on top.


  • void set_window_title ( String title )

Sets the window title to the specified string.


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("https://godotengine.org") opens the default web browser on the official Godot website.


  • void show_virtual_keyboard ( String 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).