How to Clear Text Source with Hotkey in OBS Studio

Operating text sources in OBS Studio during a live stream often requires quick updates or sudden clearing. This article provides a step-by-step guide on how to configure a custom keyboard shortcut (hotkey) in OBS Studio to instantly clear all text from a specific text source, helping you streamline your broadcast workflow using a simple, native Lua script.


Why Use a Script to Clear Text?

While OBS Studio allows you to set hotkeys to hide or show sources, hiding a source only makes it invisible; it does not delete the text inside it. If you want to keep the text source active but completely empty its contents at the press of a button, you must use OBS Studio’s built-in scripting engine.

Below is the step-by-step process to set up a dedicated “Clear Text” hotkey.


Step 1: Create the Lua Script

OBS Studio can run lightweight Lua scripts. You can create a simple script that targets your text source and replaces its text with nothing.

  1. Open a basic text editor like Notepad (Windows) or TextEdit (Mac).
  2. Copy and paste the following code block into the document:
obs = obslua
source_name = ""

function script_description()
    return "Adds a custom hotkey to instantly clear all text from a specified Text (GDI+) source."
end

function script_properties()
    local props = obs.obs_properties_create()
    local p = obs.obs_properties_add_list(props, "source_name", "Select Text Source", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING)
    
    local sources = obs.obs_enum_sources()
    if sources ~= nil then
        for _, source in ipairs(sources) do
            local id = obs.obs_source_get_unversioned_id(source)
            if id == "text_gdiplus" or id == "text_ft2_source" then
                local name = obs.obs_source_get_name(source)
                obs.obs_property_list_add_string(p, name, name)
            end
        end
        obs.source_list_release(sources)
    end
    return props
end

function script_update(settings)
    source_name = obs.obs_data_get_string(settings, "source_name")
end

function hotkey_triggered(pressed)
    if not pressed then return end
    local source = obs.obs_get_source_by_name(source_name)
    if source ~= nil then
        local settings = obs.obs_data_create()
        obs.obs_data_set_string(settings, "text", "")
        obs.obs_source_update(source, settings)
        obs.obs_data_release(settings)
        obs.obs_source_release(source)
    end
end

function script_load(settings)
    hotkey_id = obs.obs_hotkey_register_frontend("clear_text_hotkey", "Clear Text Source", hotkey_triggered)
    local hotkey_save_array = obs.obs_data_get_array(settings, "clear_text_hotkey_array")
    obs.obs_hotkey_load(hotkey_id, hotkey_save_array)
    obs.obs_data_array_release(hotkey_save_array)
end

function script_save(settings)
    local hotkey_save_array = obs.obs_hotkey_save(hotkey_id)
    obs.obs_data_set_array(settings, "clear_text_hotkey_array", hotkey_save_array)
    obs.obs_data_array_release(hotkey_save_array)
end
  1. Save the file. Name it clear_text.lua (ensure the file extension is .lua and not .txt).

Step 2: Load the Script into OBS Studio

  1. Open OBS Studio.
  2. Click on Tools in the top menu bar, then select Scripts.
  3. In the Scripts window, click the + (Plus) icon in the bottom-left corner.
  4. Navigate to where you saved clear_text.lua, select it, and click Open.
  5. Click on the loaded script in the list. Under the Script Properties section on the right, use the dropdown menu next to Select Text Source to choose the specific text source you want to clear.

Step 3: Assign Your Custom Hotkey

Now that the script is linked to your text source, you can assign a keyboard shortcut to it.

  1. Go to Settings in OBS Studio (File > Settings, or click Settings in the Controls dock).
  2. Select the Hotkeys tab from the left sidebar.
  3. In the search box at the top, type Clear Text Source.
  4. Locate the binding field for Clear Text Source.
  5. Click inside the field and press the key combination you want to use (e.g., Ctrl + Shift + C or NumPad 0).
  6. Click Apply and then OK.

Pressing your chosen key combination will now instantly wipe out all text in the selected OBS text source.