Ignore or block keyboard input?

I have a situation where I want the player to be knocked back horizontally by an enemy, which I can get to work either by applying a force or by adjusting the player.X() position. The problem is that if you hold down the “move right” key then this competes with the knock back process and the player doesn’t go far enough back.

I can make it work with object variables controlling the key presses, but is there a way to tell GDevelop to ignore keyboard input? A bit like the way you can turn off a behaviour.

Using variables to control functions is the standard way to do this.

When the player gets knocked back:

Conditions: Player is in collision with KnockBackEnemy
Actions: Do = 1 to Variable knockback

You also need something like this to reset the knockback:

Conditions: Player is NOT in collision with KnockBackEnemy
Actions: Do = 0 to Variable knockback

The player movement function should look like this:

Conditions:
Variable knockback is != 1
w is pressed

As attachment how I do it in my game. It works pretty well. Test my game and see is it what you want [url]BMMB: BioMechanic Man Boy].
I don’t think those jump speed thing in events are necessary, but test it out. And those angles you can change, because in those events player knock back obliquely upward.

Thanks for the suggestions. If everyone else is doing it with variables then that must be the way to do it. It seems like stopping the player doing anything while an animation plays is such a standard part of games that it might be built in to GDevelop.

Thinking about it, I suppose a global variable “nokeyboard” would save having to alter individual events for individual objects. Make all events that check the keyboard into sub-events of a master event checking if the value of nokeyboard is 0 or 1.

Sometimes people suggest there should be a specific command for things that people think are common.

There absolutely shouldn’t be!

Using variables to control if functions are active or not is quick and easy to do and it works. Adding in a button for every common thing you might want to do would not be any quicker, and would mean making hundreds of buttons, which would be very confusing!

This master event should just be a normal variable that is = 1 or = 0.

I disagree with previous argument. I believe a simple stop keyboard input built into g develop would be the simplest way to do some of the stuff. Because I mean let’s face it there many events were I just want an action to stop keyboard input and then resume keyboard input it’s a very simple command that could be built into g develop with minimum effort