simulate a keypress from a script

hey guys , is it possible to simulate a key press with a script like , when the game starts i want the spacebar to be pressed withtout me pressing it , i want it to be pressed from the script ! ,thanks.

This is solution:

No that I’m aware of. I can’t think why you’d need to do this though. Let’s say your current code has something like:

void Update() {

Then to “simulate” that keypress when the game starts, you’d simply have to add:

void Start() {

Or have I misinterpreted your question?

I would like to know the answer too. My issue is slightly different from adamchakov. I want the “J” key to be pressed when a rising platform is about to flatten me against a static wall. The J key will make my character shorter, so the wall won’t crush me.

The Switch() method is called, but the Switch() method takes arguments that are impossible for me to reproduce and send because the one parameter is a group of enums that have values based on the conditions of the game and character at the time of the button press. Plus, the method wasn’t made by me, so I do not know how to send the null value to invoke the Switch() method.

So, I have to simulate the button press to make the character shrink, so he doesn’t die.