Check if the player is holding the shift key

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By olli460

I have a basic game where the player can place towers on the map. Currently when they click the tower they have to select the tower again to place another one.

I want the player to be able to build multiple towers at once if they are holding the shift key but i can’t figure out how to check if they are holding it, It only seems to check it once

i assigned the shift key to the input keys under project setting and done this code to test it

if event.is_action_pressed("multi_build"):
print("Shift is pressed")

But i only get one message output, how can i check if they are holding it down?

:bust_in_silhouette: Reply From: BunnzoSteel

I don’t know if it makes a difference if you use the Input singleton directly? That is

if Input.is_action_pressed(“multi_build”)

is how I would write your example. I haven’t used the shift key in the input mapper but I can poll it directly:

if Input.is_key_pressed(KEY_SHIFT):

and that returns true every frame.

One other thing you could try is setting a latch variable, like:

If Input.is_action_just_pressed(“multi_build”):
multi_build_latch = true
If Input.is_action_just_released(“multi_build”):
multi_build_latch=false

:bust_in_silhouette: Reply From: exuin

Either check every frame in a process function whether shift is pressed or have a boolean variable that is set to true when shift is pressed and false when it is released.