Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How can I determine what key was pressed when picking up player input?

I've been able to assign Q,W,E and F keys to an action called CombatAction within the editors Inputs like so:

I've then be able to pick this up within my Character class like so:

alt text

InputComponent->BindAction("CombatAction", IE_Pressed, this, AThe_Battle_of_MaldonCharacter::CombatAction);

Which runs this:

void AThe_Battle_of_MaldonCharacter::CombatAction() {


All I need is to pick up whether they pressed Q,W,E or F within the method i.e.

void AThe_Battle_of_MaldonCharacter::CombatAction(char buttonPressed) {


Something like that.

Any help would be great :D

Product Version: Not Selected
bindings.png (13.8 kB)
more ▼

asked Jun 06 '14 at 10:43 AM in C++ Programming

avatar image

92 19 35 47

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

What you could do is this... instead of binding multiple keys to an Action Mapping, bind those keys to an Axis Mapping. The Axis Mapping allows you to assign a scale value that is returned when you press the button. Just assign a different value to each button and then do an if statement or a switch statement to handle this.

Something like:

In Editor:

Axis Mapping -

Q to scale 1.0

W to scale 2.0

E to scale 3.0

F to scale 4.0

 InputComponent->BindAxis("CombatAction", this, &AThe_Battle_of_MaldonCharacter::CombatAction);

 void AThe_Battle_of_MaldonCharacter::CombatAction(float Value) {
     if(Value > 3.5){
         // F Pressed
     }else if (Value > 2.5){
         // E Pressed
     }else if (Value > 1.5){
         // W Pressed
     }else if (Value > 0.5){
         // Q Pressed
         // do default or nothing or return

This is untested but the docs don't say the Axis Mapping is restricted to [-1,1] so I don't foresee any issues.

Hopefully this works for you!

Edit: Typo =)

more ▼

answered Jun 06 '14 at 11:22 AM

avatar image

1.6k 61 45 237

avatar image Belven Jun 06 '14 at 11:30 AM

An interesting idea, I'll use it for now but surely they should still have something like this:

function bool InputKey(int ControllerId, name Key, EInputEvent Event, optional float AmountDepressed = 1.f, optional bool bGamepad = false) {

 return false;


Only want a string or char but I'm sure there will be some documentation on it somewhere :D

avatar image AnxGotta Jun 06 '14 at 11:36 AM

I'm almost certain they don't have that. The input documentation specifically states that keys are mapped to actions or values. A Staff member can correct me if I'm wrong but I'm pretty sure a Key press passing in a char value as a parameter is not possible.


Just finished digging around in the Runtime InputCore (link) class with no luck. I'll keep browsing around though.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

The entire purpose of the Action and Axis mapping system is to abstract away the keys from the in game behaviors to make changing the default keys not require a big rework of your code and make user remapping of controls much easier. Exposing the specific key pressed goes against that intention.

For the moment, the expectation is that if you had 4 different combat actions you would map each key individually to CombatAction1, 2, etc. We do have some thoughts about being able to bind a parameter to the delegate so you could then bind CombatAction1 to CombatAction(1) or something like that, but we don't have specific plans for when such a change might be made.

I have to give AnXgotta credit for a sneaky idea, but I wouldn't recommend it. The reason for this is that if you had both Q and W pressed (for example) the axis value for the given frame would be 3 and the code would treat it as an E.

Edit: As for your question about InputKey, yes, you could circumvent the input binding system in general and in your PlayerController override InputKey yourself. I wouldn't generally recommend it, but it is an option available to you in 4.2 (they weren't virtual before that).

more ▼

answered Jun 06 '14 at 02:15 PM

avatar image

Marc Audy STAFF
2.2k 43 35 95

avatar image AnxGotta Jun 06 '14 at 02:30 PM

I'm a bit surprised the input event adds the values, that's pretty interesting. Good info Marc... even thought it's not my question I appreciate the detailed explanation.

avatar image Marc Audy STAFF Jun 06 '14 at 02:35 PM

If you think about the typical mapping purpose of the keys to axis with scale is to create something like MoveForward or MoveRight axes with WASD where pressing W is forward, and S is backwards. So you make W scale +1 and S scale -1 and then if both are held they add together and you end up with 0.

It can be tricky though, because if you're not careful and you have both W and up arrow key mapped to MoveForward with scale +1 then you actually end up with double forward movement unless you're capping it in your code.

avatar image AnxGotta Jun 06 '14 at 02:40 PM

That implementation makes sense. Thanks man.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question