| Home Page | Recent Changes | Preferences

Binding Keys

To bind a key means to assign an in-game command with that of a button on a keyboard, mouse or joystick (or other input device).

Binding Keys

There are two methods for binding keys to commands. Both work in all Unreal Engine games (confirm this please).

Using the in-game console.

The syntax for the command is:

 set input <key> <command>

For example:

 set input Z Behindview 1 | OnRelease Behindview 0

Note, for Deus Ex, the syntax is (Deus Ex uses Extension.InputExt rather than Engine.Input for its input class):

 set inputext <key> <command>

So, if I wanted to bind the g key to activate god mode, the syntax would be:

 set inputext g god

Edit the User.ini file

The other method is to edit the User.ini? file. Under the section [Engine.Input], there should be many lines like this:

 W=MoveForward

Keys can easily be bound to commands by finding the appropriate line and editing it. The syntax is

 <key>=<command>

For example:

 Z=Behindview 1 | OnRelease Behindview 0

(In both cases, the keybind makes it such that when the 'Z' button is held down, it switches to BehindView (third-person view). When you release the key, it goes back to normal (first-person) view.)

Multiple commands can be bound to one key by separating the commands with the pipe character ("|").

Other useful binding commands are PipedSwitchWeapon and SwitchToLastWeapon. Consider the following bind.

 V=PipedSwitchWeapon 3 | PipedSwitchWeapon 7

This will bind the Bio Rifle and the Flak Cannon to the V key such that if you have both weapons you will be able to toggle between them by repeated presses of the V key. If you only have a single weapon out of the two pressing the V key will switch to the weapon you have.

 R=SwitchWeapon 1| AltFire | OnRelease SwitchToLastWeapon

This binding will cause the R key to bring up the shield when the key is pressed, and then revert to the weapon you were holding when you pressed the R key.

Bindings not only work with keys, but also for mouse and joystick buttons:

 MouseWheelDown=NextWeapon
 Joy1=Fire

But how do Epic/DE assign keys in the Configure Controls menus?

This differs from version to version of the Unreal Engine. Unreal Tournament has third-party developer (i.e. mod makers) key bind support - this means we can add new keys to the bottom of the pre-existing Configure Key list.

Games such as Deus Ex, if you want to define a new key, you have to replace the entire menu(!) which is a more inefficent use of code. However, both methods work - but you'd be made to replace the entire Configure Key menu in UT!

How to add keybinds to UT

UTExtraKeyBindings - This class allows you to set your button names and aliases so players can configure their own controls.

How to add keybinds to UT2003

As of version 2179, UT2003 now has a similar class - GUIUserKeyBinding.

Using Aliases

An alias is a short command that represents one or more commands. Aliases can be made in the User.ini file, again under the [Engine.Input] section.

To create an alias, find an empty alias line like this one:

 Aliases[36]=(Command=,Alias=)

If there aren't any, then make your own, adding a new number. The line can be modified to make an alias. The syntax is:

 Aliases[<number>]=(Command="<command(s)>",Alias="<alias name>")

For example, say I want to make a new command called "wireframe" that turns on wireframe mode. This might be how I go about doing it:

 Aliases[36]=(Command="rmode 1",Alias="wireframe")

Toggle Commands

Aliases can be used in a clever way in combination with binds. Suppose I want to make it so that pressing X will toggle between wireframe mode and normal mode. It might seem rather difficult at first, but with a couple of aliases and a keybind it is quite simple:

 Aliases[38]=(Command="rmode 1 | set input X nowireframe",Alias="wireframe")
 Aliases[39]=(Command="rmode 5 | set input X wireframe",Alias="nowireframe")
 X=wireframe

The way this works is, pressing X runs the command "wireframe". This alias sets the rmode to wireframe, and then changes the X bind to run the command "nowireframe". When X is pressed again, the command "nowireframe" reverts the rmode back to normal, and it rebinds X to "wireframe" again. With a little modification, this method can easily be extended to cycle between several commands.

Content that needs to pay a visit to the UnrealEd Goblin

Aliases
Keys must have an alias function name. This alias will call an exec function in your player class if you have one. This is good for one time use functions like QSFire()
Buttons
If you need to know when the player releases or is holding a button, you must have an input button variable, and an alias binding.
Input Button Variable
the player class must contain your button variables (var input byte bMyButton;)...the button is true when held, false when not.
Alias Binding
In order to prevent 'Bad button command' from logging when you press your button, you have to bind it. To do this while inside UT press '~' to bring up your console, then type PREFERENCES <enter> to bring up Advanced Options. Select ADVANCED, KEY ALAISES, ALIASES, then go down to an empty space and enter your alias name and the command parameter BUTTON bMyButton.

Related Topics

Discussion

ZxAnPhOrIaN: I use the menu and windows key on my keyboard for the behindview 0 and 1 commands.

Bcladd: Don't mean to seem dim but I cannot find the class GUIUserKeyBinding anywhere in my 2199 source tree nor is it referenced in any of the source code. I am guessing the reference to it above should probably be eliminated.

PleaseLoveMe: No, it's there. Check Object → GUI → GUIUserKeyBinding in the object tree. I recommend using WOTgreal for editing uscript because it makes it easier to find such things.

Tarquin: How do you create a binding that toggles, eg "Rmode 1 / rmode 5"?

Mychaeel: You can't. The only thing you could do is make a binding that switches to "rmode 1" when pressed and back to "rmode 5" when released: "rmode 1 | onrelease rmode 5".

Tarquin: Pity :( I remember Quake had a neat trick of the binding for the keypress creating the binding for the release, and vice versa.

Wormbo: It's possible with aliases:

Aliases[38]=(Command="rmode 1 | set input X nowireframe",Alias="wireframe")
Aliases[39]=(Command="rmode 5 | set input X wireframe",Alias="nowireframe")
X=wireframe

DemonThing: Alright, I clarified the article a bit (I think), and added a little section on aliases. (Thanks Wormbo for pointing that out)


Category To Do

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

FAQs

Help Desk

Mapping Topics

Mapping Lessons

UnrealEd Interface

UnrealScript Topics

UnrealScript Lessons

Making Mods

Class Tree

Modeling Topics

Chongqing Page

Log In