Skip to main content

How to Open the On-Screen Keyboard in a Batch Script

The On-Screen Keyboard (OSK) is a crucial accessibility feature in Windows, allowing users to type without a physical keyboard. It is essential for touchscreen devices, kiosk environments, or for troubleshooting situations where a keyboard is malfunctioning. From a batch script, you can launch the OSK to assist a user or to prepare a system for a specific interactive task.

This guide will teach you how to use the simple, built-in osk.exe command to launch the On-Screen Keyboard. You will learn the difference between a blocking and non-blocking call and why using the START command is the recommended method for launching it from a script.

The Core Command: osk.exe

The executable file for the On-Screen Keyboard is osk.exe. This program is a standard component of Windows and is located in the System32 directory. Because this folder is in the system's PATH environment variable, you can run the command simply by its name.

Syntax: osk

Basic Example: Launching the On-Screen Keyboard

This is the most direct way to run the program. However, like many GUI applications, it can be a blocking command, meaning your batch script will pause until the OSK is closed.

@ECHO OFF
ECHO --- Launching the On-Screen Keyboard ---
ECHO.
ECHO The script will now pause and wait for you to close the OSK window.

osk

ECHO.
ECHO --- On-Screen Keyboard was closed ---
ECHO The script has now resumed.
PAUSE

When you run this script, it will open the On-Screen Keyboard and halt execution. The "OSK was closed" message will not appear until you have completely closed the OSK application window.

The Better Method: Using the START Command

For almost all scripting purposes, you want to launch the OSK and then allow your script to continue running or exit. This is an asynchronous launch, and the command for it is START.

Syntax: START "" osk

  • START: The command to launch a new process asynchronously.
  • "": A required dummy "title". The START command's first quoted string is always treated as the title for a new window. You must provide a title first, even if it's just empty quotes.
  • osk: The program to run.
@ECHO OFF
ECHO --- Launching the On-Screen Keyboard in the Background ---
ECHO.

START "" osk

ECHO The main script is continuing immediately without waiting for the OSK to close.
ECHO.
PAUSE

When this script runs, the On-Screen Keyboard will open, and the batch script will immediately continue to the next line without pausing. This is the recommended method for all scripts.

Common Pitfalls and How to Solve Them

  • Script Pauses Unexpectedly: This is the most common issue, caused by running osk directly instead of using START.

    • Solution: Unless you explicitly want your script to halt, always use START "" osk. This ensures non-blocking behavior.
  • Administrator Rights: Launching the On-Screen Keyboard is a standard user function. This command does not require administrator rights.

  • Forgetting the START Title: A common syntax error is to run START "osk". While this might work for a simple command, it's incorrect. If your command had a path (e.g., START "C:\MyApp\app.exe"), it would fail.

    • Solution: Get into the habit of always providing the dummy title first: START "" ....

Practical Example: A Kiosk or Touchscreen Setup Script

This script prepares a machine for a user who will be interacting via a touchscreen. It launches a primary application and also opens the On-Screen Keyboard to ensure they can provide any necessary text input.

@ECHO OFF
TITLE Kiosk Mode Launcher
CLS

ECHO --- Initializing Kiosk Environment ---
ECHO This machine will be configured for touch-only input.
ECHO.
TIMEOUT /T 3 > NUL

ECHO Launching the main application...
REM (This would be the path to the main kiosk software)
START "" "C:\Kiosk\App.exe"

ECHO.
ECHO Launching the On-Screen Keyboard for accessibility...
START "" osk

ECHO.
ECHO --- Setup complete. ---

Conclusion

Launching the On-Screen Keyboard from a batch script is a simple and effective way to provide accessibility or enable text input on devices without a physical keyboard.

Key takeaways:

  • The executable is osk.exe.
  • Running osk by itself is a blocking command that will pause your script.
  • The recommended method is to use START "" osk, which launches the OSK asynchronously and allows your script to continue without waiting.