Skip to content

Using a Joystick or Gamepad as selection source

kmcnaught edited this page Aug 16, 2022 · 1 revision

This page explains how to use a joystick or gamepad button as the key and/or point selection method in OptiKey. The joystick or gamepad button can be an actual USB game controller, an assistive gaming device such as the Xbox adaptive controller, or a switch interface device programmed to behave as a joystick or gamepad.

Why use joystick or gamepad input?

If you've tried using OptiKey with a physical switch as the key and/or point selection source, then you probably have encountered a problem. If you program your switch to send a keystroke, say a, and then you try to type the word Hello, what you will actually see in your word processor is aHaealalao. Because the word processor recognizes the a keystrokes sent by your switch interface, you end up with a interspersed with the characters you actually want.

For many use cases, it works to simply use a different key. Sometimes the insert key is chosen. Often a high number function key, such as F13, will work.

For some target applications, such as terminal emulators (e.g. MobaXTerm, Git Bash), even these high-numbered function keys are interpreted as input. In the case of most terminal emulators, you will get a ~ when pressing any of F13-F24.

Using a joystick/gamepad button as an input circumvents all of these problems for the majority of applications. Unless you are trying to play a game, the gamepad buttons don't do anything, and therefore we can use them as a selection source in OptiKey without unintended side effects.

Setting up Optikey with your hardware

What hardware will work?

Essentially any USB device that presents itself as a game controller or gaming joystick should work. The Xbox adaptive controller has been tested and works successfully. Switch interfaces that can send joystick/gamepad input will also work. X-keys switch interfaces have been used successfully, but they are tricky to program; see notes on this page.

If you need help identifying the correct controller and button name or are having any other issues, check out the tools mentioned in Diagnostics

Navigating to the Management Console

With OptiKey running, open the Management Console by pressing Alt + M or right-clicking on OptiKey and selecting "Management Console." Navigate to the "Pointing & Selecting" tab. Scroll down to the section labeled "Selection."

alt text

Picking the selection source

If your game controller uses XInput (according to the test you did with TestControllers.exe), select "Gamepad button (XInput)" for Key selection source. If your controller uses DirectInput, instead select "Gamepad button (DirectInput)."

See the red box labeled "1" in the above screenshot.

Selecting the gamepad controller

For "Key selection gamepad controller," most users can select "All XInput controllers" or "All DirectInput controllers." This setting will take input from any connected controller. If you're just using one controller with your computer, the all controllers setting is recommended.

If you're using multiple controllers with your computer and want only one of them to activate OptiKey, select the specific controller you're using. Consult the output of TestControllers.exe if you need help finding the name of your controller.

Refer to the orange box labeled "2" in the above screenshot.

Selecting the gamepad button

For "Key selection gamepad button," pick the controller button you want to use. Consult the output of TestControllers.exe to find the button name or number.

Refer to the green box labeled "3" in the screenshot above.

Setting the Point selection source

The first three settings in the Selection section ("Key selection source," "Key selection gamepad controller," and "Key selection gamepad button") all control how you select keyboard keys. If you you also want to use your gamepad controller to select points on the screen, make the same selections for "Point Selection source," "Point selection gamepad controller," and "Point selection gamepad button."

Diagnostics

Using TestControllers.exe

There are two distinct protocols that game controllers can use to communicate with the computer: DirectInput and XInput. Both work with OptiKey, but you need to know which one your controller is using. You also need to know the name of the button you are pressing. TestControllers.exe can provide both pieces of information.

To run TestControllers.exe, navigate to where OptiKey is installed. With OptiKey Pro on Windows 10, this is C:\Program Files (x86)\Optikey Pro, but it may be different if you are using a different version of OptiKey or of Windows.

Then double-click on the file TestControllers.exe. This will open a console window similar to the one shown below.

alt text

This example shows that a DirectInput controller called fc13e240 is connected. Buttons 1, 2, and 3 have been pushed and released in sequence.

Make note of whether your controller is DirectInput or XInput. Also make note of the name/number of the button that you want to use as a trigger.

If your controller shows up as both DirectInput and XInput, it is recommended to use XInput.

The Windows game controller properties

If your controller is not showing up in TestControllers.exe, or if you're having other issues with your controller, you can also use the Windows game controller properties window to help debug the problem.

From the Start Menu, search for Set up USB game controllers and open the app.

alt text

A window will open with a list of game controllers. Select the one you want to use and click Properties.

alt text

When you click on properties, you should see a window similar to this.

alt text

Press a button on your controller. If you see a button light up on screen, then your controller is set up and should work with OptiKey. You can also note the button number, as you'll want to use this when configuring Optikey.

Clone this wiki locally