Gamepad to Keyboard/mouse/xbox360(gamepad) emulator
Based on code by:
and fake Xbox code from:
Modified to use SDL2 by: Nikolai Wuttke & Shanti Gilbert for https://github.com/EmuELEC/EmuELEC Interactive text entry added by Robin Duxfield
List of keycode values start here:
mkdir build cd build cmake .. cmake --build . strip gptokeyb
gptokeyb provides a kill switch for an application and mapping of gamepad buttons to keys and/or mouse. It also provides an xbox360-compatible controller mode.
must be set so the gamepad buttons are properly assigned within gptokeyb, e.g.
is automatically set in Emuelec
sets the button used as hotkey.
button is automatically selected as hotkey, unless overridden by
export TEXTINPUT="my name"
assigns text as preset for input so that
is automatically entered, once triggered
should be sent to close the app before kill mode is processed, which can be used on Linux pcs
Command Line Options
selects xbox360 joystick mode
select interactive text input mode (see below)
specifies button mapping for keyboard and mouse functions, e.g.
of the command line options specifies that the default button mapping file should be used, which is
-1 <application name>
-k <application name>
provides the name of the application that will be closed by pressing
sudo kill -9 <application name>
will be used to close the application instead of
killall <application name>
Keyboard Mapping Options
The config file that specifies button mapping for keyboard and mouse functions takes the form of
%s = %s
. Any comment lines beginning with
are ignored. Deadzone values are used for analog sticks and triggers, and may be device specific.
affects the speed of mouse movement, with a larger value causing slower movement.
mouse_scale = 8192
generally works well for RK3326 devices.
gamepad button = \"
can be used to unassign a button.
values must be in lowercase and simple text strings are translated into key codes, for example
Default mappings are:
start = enter guide = enter a = x b = z x = c y = a l1 = rightshift l2 = home l3 = mouse_right r1 = leftshift r2 = end r3 = mouse_left up = up down = down left = left right = right left_analog_up = w left_analog_down = s left_analog_left = a left_analog_right = d right_analog_up = end right_analog_down = home right_analog_left = left right_analog_right = right # Old deadzone code deadzone_y = 2100 deadzone_x = 1900 mouse_scale = 512 mouse_delay = 16 # New deadzone code, this will overwrite the above deadzone code behaviour # Choices of: axial, radial, scaled_radial, sloped_axial, sloped_scaled_axial, hybrid deadzone_mode = scaled_radial deadzone = 2000 deadzone_scale = 8 deadzone_delay = 16 ## An alias for mouse delay
You can additionally slow the cursors speed temporarily by defining a button as
. The rate at which is slows is controlled by
l1 = mouse_slow mouse_slow_scale = 50 # 50%
The scale is proportional, so 75 will run the mouse at 75% of the mouse movement. So for example 7 becomes 5 with
mouse_slow_scale = 75
Mouse control via Analog stick
The mouse can be controlled via the analog sticks, either the left or the right if the device has one.
left_analog_up = mouse_movement_up # the rest of these do nothing: left_analog_down = mouse_movement_down left_analog_left = mouse_movement_left left_analog_right = mouse_movement_right
You can only have the left or right analog stick set as mouse movement at one time. If both are set, it will default to the left stick.
You can control the behaviour of the analog stick and the deadzones, we have several different deadzone scaling modes which we used the implementation of from here: https://github.com/Minimuino/thumbstick-deadzones
is the minimum amount the stick needs to move before it registers,
is the amount the mouse will move at the sticks maximum.
is the delay between moving the mouse measured in milliseconds.
# Choices of: axial, radial, scaled_radial, sloped_axial, sloped_scaled_axial, hybrid deadzone_mode = scaled_radial deadzone = 2000 deadzone_scale = 8 deadzone_delay = 16 ## An alias for mouse delay
Dpad as mouse control
You can control the mouse with the dpad, keeping with the normal configuration code, and the mouse movement rate is adjusted by setting
. The above
keybinding works in conjunction with the mouse control as dpad, and you can still control the mouse via an analog stick.
up = mouse_movement_up dpad_mouse_step = 7
Note: Enabling mouse control via dpad will disable all keybindings on the dpad.
Hotkey + Button for additional Key Assignments
An additional 8 keys can be assigned through Hotkey combinations for
buttons. Hotkey+button assignments are specified by adding
for the appropriate button (see default mappings below). The keys can use the same
modifiers by including a separate line that indicates
The following example assigns
to the combination of
a_hk = f4 a_hk = add_alt
Default mappings are:
a_hk = enter b_hk = esc x_hk = c y_hk = a l1_hk = esc l2_hk = home r1_hk = enter r2_hk = end
Sometimes key presses require a combination of
plus the key. These combinations can be specified by adding a separate line that indicates
respectively. Modified keys can '''not''' be repeated at present.
The following example assigns
a = x a = add_ctrl
A simple keyboard key repeat function has been added that emulates automatic repeat of a keyboard key, once it has been held for at least an initial
, at a regular
. Key repeat works for one key at a time only (the first key that is pressed and held is repeated, and holding another key will not cause that to repeat, unless the first key is released). Key repeat has not been set up to work for analog triggers (L2/R2) at the moment.
The default delay and interval are based on SDL1.2 standard and can be adjusted with
Key repeat is configured by adding
gamepad_button = repeat
as a separate line, in addition to the line
gamepad_button = keyboard key
. The following assigns arrow keys with key repeat to the gamepad d-pad and left analog stick.
up = up up = repeat down = down down = repeat left = left left = repeat right = right right = repeat left_analog_up = up left_analog_up = repeat left_analog_down = down left_analog_down = repeat left_analog_left = left left_analog_left = repeat left_analog_right = right left_analog_right = repeat
Text Entry Options
Text entry is possible, either by sending a preset (e.g. to enter your name to begin a game) or via an interactive input mode that's similar to entry of initials for a high score table
Text entry options are enabled by environment variable settings
export TEXTINPUTPRESET="My Name" # defines preset text to insert export TEXTINPUTINTERACTIVE="Y" # enables interactive text input mode export TEXTINPUTNOAUTOCAPITALS="Y" # disables automatic capitalisation of first letter of words in interactive text input mode export TEXTINPUTADDEXTRASYMBOLS="Y" # enables additional symbols for interactive text input
Interactive input mode is also enabled by command line option
Preset Text Input
Text Entry preset mode is enabled by
environment variable whereby a name preset can be easily entered whenever a game displays a text prompt. When Text Entry is triggered with
, the preset text is entered as a series of key strokes.
Text Entry preset mode also assigns
to send preset
Interactive Text Input
Interactive Text Entry mode is enabled by launching GPtoKEYB with command line option
or by environment variable
, and is triggered with
. Once activated, Interactive Text Entry mode works similarly to entering initials for game highscores, with
switching between letters for the currently selected character,
moving to next character,
deleting and moving back one character,
cancelling interactive text entry, and
to confirm and exit interactive text entry.
in interactive text entry mode and exits interactive text entry.
Interactive Input Mode Controls
START+D-PAD DOWN to activate once activated D-PAD UP = previous letter D-PAD DOWN = next letter D-PAD RIGHT = next character D-PAD LEFT = delete and move back one character L1 = jump back 13 letters for current character R1 = jump forward 13 letters for current character A = send ENTER key and exit mode SELECT/HOTKEY = cancel and exit mode (deletes all characters) START = confirm and exit mode (also sends ENTER key)
By default Interactive Text Entry mode will start with
as the first letter and immediately after a space, and
otherwise, unless environment variable
is set, whereby all letters will start as
By default Interactive Text Entry mode includes only a limited number of symbols "[space] . , - _ ( )", and a full set of symbols is included with environment variable
Interactive Text Entry relies on the game providing a text prompt and sends key strokes to add and change characters, so it is only useful in these situations. Interactive Text Entry is automatically exited when either
are pressed, to minimise issues by accidentally triggering this mode.