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.
- Open OBS Studio and navigate to the Sources dock.
- Click the + (plus) icon and select Text (GDI+) (Windows) or Text (FreeType 2) (macOS/Linux).
- Name the source something recognizable, such as
Keystroke Display, and click OK. - 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.
- In the top menu of OBS Studio, click on Tools and select Scripts.
- In the Scripts window, click the + (plus) icon in the bottom-left corner of the Loaded Scripts tab.
- Locate your custom
.luakeystroke script file on your computer and click Open. - 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.
- In the script’s settings pane, find the dropdown menu labeled Text Source (or similar, depending on your script’s code).
- Select the
Keystroke Displaytext source you created earlier. - 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.
- Apply a Monospace Font: In the properties of your Text source, choose a monospace font like Consolas or Courier New. This ensures that keys align perfectly when stacked or listed.
- Add Background and Borders: Enable the Background Color option in the text properties and adjust the opacity to create a clean, semi-transparent backing box for the keys.
- Add Outlines and Shadows: Add a text outline or drop shadow within the text properties to make the keystrokes readable against bright gameplay or busy backgrounds.
- Apply OBS Filters: Right-click the Text source, select Filters, and add a Crop/Pad filter to restrict the display area, or a Scroll filter if your script outputs a continuous horizontal stream of inputs.