Can I use SendMessage() to fool a script into thinking that a key has been pressed?

I would like one script to tell another script that a key has been pressed. This is basically what I would like to do:

someScript.SendMessage(Input.GetKeyDown("space"));

I’m aware that there are alternative solutions that would let me achieve the same effect, but let’s just say that, for some arbitrary reason, SendMessage is my only option, and I absolutely must convince a script that it is receiving the Input.GeyKeyDown(“space”) message.

Is this possible?

Unity scripts don’t receive any events for mouse or keyboard actions. They just check the current status of some input flags in the update function. So, you CAN’T send a message to a script about an input action.

If the script you are trying to fool is opensource, you can modify it so that it can read from a global variable instead of reading from Input.GetKeyDown(“space”). Then all you need to do is set this global variable wherever you like.

If that script is 3rd party and has no source code, I don’t think you can fool it without hacking into the compiled IL code which I don’t have any experience.