Frictional Games Forum (read-only)

Full Version: Key-Press detection and Game speed control in HPL3
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys, two quick questions about HPL3. I can't seem to find info in the wiki about this.
Are there any new functions related to key-press detection or how to control the game speed? just like we do in dev mode.
Thanks.

I may be working in something but I don't wanna reveal anything until I'm completely sure I can do it. You know what I mean.
There are a couple of ways to detect key presses.

The first and easier way is to watch the OnAction function of your map script for whenever the player initiates an action, e.g. eAction_Forward, eAction_Interact, eAction_Cancel (the eAction enumeration is in the "script/base/InputHandler_Types.hps" file if you want to see the full list of actions available). The benefit to this is that the key is automatically routed through the game's keybindings, so you can always detect a particular action regardless of what key it is bound to. The downside to this approach is that you are limited to only using existing actions in the game (though you can add more if you know how).

To check against a particular action, you compare the alAction parameter against whichever action you are watching for:

Code:
bool OnAction(int alAction, bool abPressed)
{
    // Check if the interact action was started (and if the key was pressed rather than released)
    if (alAction == eAction_Interact && abPressed)
    {
        // Do stuff...
    }
}

The other way is a bit more involved (and I haven't tested it yet myself, so I can't vouch for its effectiveness). You can get an instance of the iKeyboard object and manually detect if certain keys are being pressed (using the eKey enumeration). This has the benefit of allowing you to check the state of any key you want, but the downside of possible collisions with existing keybindings. You would also have to put it in your map's Update script if you wanted to continuously check for key presses which could potentially affect performance (though probably not by much).

Code:
void Update(float afTimeStep)
{
    iKeyboard @keyboard = cInput_GetKeyboard();

    // Check if the key is pressed (note that this will return true for as long as the key is held down)
    if (keyboard.KeyIsDown(eKey_E))
    {
        // Do stuff...
    }
}
Great. I'll look into it.
rep++

it worked.