Check how many keys are pressed

I could go with variable for each key
For example if my game uses arrows and ZXC
Then i could go with making event for each key to add 1 to variable when pressed
And subtract 1 from it when released

But is there a way to go with it for any key pressed?

So like i don’t need to define which keys to check but it would just count any kay press as +1 to variable or something?

Hello, ZeroX4

Maybe with this conditions?

My first inclination is to do something like the following:

Define an array with all the keys that can be pressed:

image

with events using key pressed (text expression):

But for some reason it only seems to detect up to 3 simultaneous key presses. Not sure if that’s a limitation with GDevelop or my VM.

1 Like

Keyboards are all different. I have a lightweight cheap Microsoft. It can only do like 4 keys at a time per group of like 5 side by side keys. Meaning it can detect only 4 of the letters in qwert at one time. I don’t know how many it can detect in total. My keyboard seems to be split in half and by row.

1 Like

@Keith_1357 They are not
There are only few design templates for keyboards
Where most cheap ones have keys on “lines”
On which multiple keys function
Most common line is for 1 q a z x c v keys
And if something happen to that line all that keys malfunction
Basically this i mean

So pressing keys where each is on different line you won’t have problem of it limiting only to few keys

@MrMen
@Rasterisko

I know exactly that i can add keys which could be pressed
I just described it in my question
So all your answers kinda repeats that

What i mean is is there a way to have it with any key pressed
Like i do not need to pre define ones that can be used

I would go with any key pressed/released condition
But now is the problem of doing it with and without trigger once
With trigger once if i would go for adding/subtracting to variable
It would get stuck on 1st key
Without trigger once it would spam that var from 1 to 100 in few secs

So i wonder is there a way to make work for all keys and not one any1 would need to define

If that’s not what you’re after, then I’d suggest you use a javascript event with a key press listener (not sure what the javascripters call a function called/invoked by an event listener).

Some user on discord asked yesterday how to limit his game to be able to have only two keys pressed at once and do not take any input afterwards

I was perfectly able to guide him to add 1 to variable for each key pressed
Which needed to be defined in events
And it worked perfectly fine for him

But I was simply wondering is there a way to streamline that process into just making via events it would detect any key pressed without pre defining them
Because i see how ppl may find it useful

I do not really need it i just wanted to arm myself from possible ready answer in case someone else need it in future

I would just add keys to array check if key pressed exist using last key pressed
And on top of that check if child with key name exist then add it to array
And only if child count is less than 2
I mean that is my general idea but this is as far as i am willing to go for something that is not for me and MAYBE someone else will ever need

But THX for suggestion

1 Like