How to Show Keystrokes in OBS Studio with Lua

This guide explains how to set up and use a custom Lua script in OBS Studio to display a stylized, real-time keystroke history overlay on your stream or recording. You will learn how to prepare your OBS scene, load the Lua script, link it to a text source, and customize its visual appearance to match your broadcast’s aesthetic.

Step 1: Prepare the Text Source in OBS Studio

Before loading the script, you need a text element in OBS to display the keystrokes.

  1. Open OBS Studio and navigate to the Sources dock.
  2. Click the + (plus) icon and select Text (GDI+) (Windows) or Text (FreeType 2) (macOS/Linux).
  3. Name the source something recognizable, such as Keystroke Display, and click OK.
  4. Leave the text field empty for now, configure your preferred font, and click OK.

Step 2: Load the Custom Lua Script

OBS Studio has a built-in scripting engine that supports Lua files.

  1. In the top menu of OBS Studio, click on Tools and select Scripts.
  2. In the Scripts window, click the + (plus) icon in the bottom-left corner of the Loaded Scripts tab.
  3. Locate your custom .lua keystroke script file on your computer and click Open.
  4. The script will now appear in the loaded list, and its customizable settings will load in the right-hand pane.

Step 3: Configure the Script Settings

To make the script work, you must link it to the text source you created in Step 1.

  1. In the script’s settings pane, find the dropdown menu labeled Text Source (or similar, depending on your script’s code).
  2. Select the Keystroke Display text source you created earlier.
  3. Configure the script-specific options. Common settings include:
    • History Limit: The maximum number of keys shown on screen at once.
    • Fade Time: How many seconds a keystroke remains visible before disappearing.
    • Button Formatting: Settings to display keys as uppercase, lowercase, or represented by symbols (e.g., arrow keys).

Step 4: Stylize the Keystroke Overlay

Since the script outputs plain text, you must use OBS’s native text and filter settings to style the overlay.