0 votes

Hi,
I'm working on a prototype for a 2D sidescroller game and I'm having some problems making the player shoot and run at the same time.
The overview is:
1. While the player is holding the "Shift" key, the player starts to run. As soon the player releases the "Shift" key, it starts to walk instead. This part is working as intended.
2. If the player presses the "KEYKP2" (Numberpad 2), it shoots a projectile. This is working as intended in every state but the "Running" state, where the player is also holding the "Shift" key.
I've tried the solution described in Godot Documentation, but to no avail.

The code is written as follows:

    if event is InputEventKey and event.pressed:
        print("pressed: " + String(event.scancode))
        if event.scancode == KEY_KP_2:
            print("KP_2 pressed")
            if event.shift:
                print("Shift+KP_2 pressed!")
                return true

The outputs:
1. When I press the KEYKP2 key, it prints "16777352";
2. When I press the Shift key, it prints "16777237";
3. When I press the Shift and KEY
KP2 at the same time, it prints "16777234"

As shown, I'm having a hard time to detect the "Shift+NP2" press. Is there a specific scancode for "Shift+KP_2"?

Regards,
Lucas Sene

in Engine by (28 points)

2 Answers

0 votes

Replace the last if block with this:

if Input.is_key_pressed("shift"):
         print("Shift+KP_2 pressed!")
                return true

Of course you have to add action "shift" in the project settings.

by (217 points)

Thanks magicalogic, but the method iskeypressed asks for a KeyList param, and does not accept a string. Nevertheless, I think that my problem may be a bug.

Sorry for the misleading answer but i meant Input.isactionpressed("shift")
having added action "shift" as action.

0 votes

I think that this problem may be a bug:

In the InputMap tab inside the Project Setting, when I try to create an action with Shift + any key, it works with any key but the number on the numeric keypad. When I try, for example, Shift + KP 2, the popout window shows the "Down" key as result. This happens with any of the number keys on the numeric keypad.

Assigning Shift + any key to the action. Working as normal.
Shift + Any key

Assigning Shift + any number in the numeric keypad. It shows "Down" instead of "Shift+KP2". The engine cannot detect this combination of keys.
Shift + KP 2

by (28 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories