By default, UDK only supports two actions for a button:

  • Pressed
  • Released

This tutorial enables five:

  • Pressed
  • Released
  • Double Tapped
  • Held
  • Released after being held.

Though you could add a sixth, seventh or combination system.
The other benefit is that all the button logic is much easier to follow, since it is now located in one function.

The following is code based on what I use.
It is one of several ways to go about it.

Your custom player controller:

class xxxPlayerController extends UDKPlayerController;


Your custom player input class:

class xxxPlayerInput extends UDKPlayerInput within xxxPlayerController

var bool bMyButton, bMyButtonPressed, bMyButtonHeld, bMyButtonWasHeld, bMyButtonReleased, bMyButtonDoubletapped, bOld_MyButton;
var float LastPressedMyButtonTime;

function MyButtonActions(float DeltaTime)
    bMyButtonPressed = bMyButton && !bOld_MyButton;
    bMyButtonDoubletapped = false;
    if (bMyButtonPressed)
        if (WorldInfo.TimeSeconds - LastPressedMyButtonTime < DoubleClickTime)
            bMyButtonDoubletapped = true;
            LastPressedMyButtonTime = WorldInfo.TimeSeconds;

    bMyButtonWasHeld = bMyButtonHeld;
    if (bMyButton && bOld_MyButton && (WorldInfo.TimeSeconds - LastPressedMyButtonTime >= DoubleClickTime))
        bMyButtonHeld = true;
        bMyButtonHeld = false;

    bMyButtonReleased = !bMyButton && bOld_MyButton;

    if (bMyButtonDoubletapped)
            // do something special
    else if (bMyButtonPressed)
            // do something
    else if (bMyButtonHeld)
            // do alternate something
    else if (bMyButtonReleased)
        if (!bMyButtonWasHeld)
            // do another something
            // do another alternate something

    bOld_MyButton = bMyButton;

event PlayerInput( float DeltaTime )

    // handle my custom button

simulated exec function MyButton()
    bMyButton = true;

// FIXME - stop using 'Un' as a prefix for momentary inputs being released
simulated exec function UnMyButton()
    bMyButton = false;

At the end of \UDKGame\Config\DefaultInput.ini :

;My Custom Bindings

.Bindings=(Name="GBA_MyButton",Command="MyButton | onrelease UnMyButton")

You could use “Command=”Button MyButton” instead, but the norm seems to be Command=”MyButton | onrelease UnMyButton”.



9 thoughts on “Tutorial: Advanced Button Actions

  1. Trying to get this right. Is there a way to bind the key(I want to use “H”) without editing the .ini file?
    I want to just add a jump to one of these functions at a time, but udk keeps giving me errors.m How to actually make this DO something?

  2. If this all happens in the player controller, how do I tell it to active stuff that is happening in other classes, say for example a MyWeapon.uc ?

  3. PlayerInput/PlayerController – same difference.
    Get a reference to you weaponr and go to it.

    if ((Pawn != None) &amp;&amp; (MyWeapon(Pawn.Weapon) != None))

    You could make several functions or simply send the action as a function variable – what ever works for you 🙂

  4. Hi, very good tutorial! What about if i want to make difference regarding the state the player is. double pressed A for instance is not the same function for walking and fighting states. Many thanks.

    1. You could add a check for the state ( IsInState(SomeState) ? ) or override the MyButtonActions() function inside the state you want to use it in. Have a look through the PlayerController / UTPlayerControler for examples

      1. Hi, thanks for answering! First i tried second solution but i had problems with accesing states in Controller from input class. The problem was that at the moment of overriding. Now i’m trying to catch some combo combinations in the input class and then call an overriden function depending on the button pressed. If you now where i can get some of this code quickly, it will be very helpful. Thanks 🙂

  5. Hi, I need to config an double click dusty run (like megaman). How can I configure it to double “D”?

    Is it correct?=

    .Bindings=(Name=”GBA_Dusty”,Command=”bMyButtonDoubletapped Axis aStrafe Speed=+3.0 | bMyButtonHeld GBA_StrafeRight”)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s