Calling preset Button OnClick events from another script

Hi everyone.
So, i have a UI Button, that makes some actions when pressed. Those actions are set by the interface, not by a code. And i have a Script, that handles pressing keys on keyboard.

I need the Script to “press” the Button (execute all commands attached to it), when a Key is pressed. Is there a way to do so? I can’t find any built-in function, associated with buttons, that would handle that.

Also, to manually run the click event, you get the reference to the button and then you can run.


You’re looking at this from the wrong perspective: The keyboard script shouldn’t activate the button, the keyboard script should activate whatever function the button also happens to activate.

For example, instead of

Keyboard script -> Button script -> Action

You should have

Button script -> Action

Keyboard script -> Action


I think, leave the key script separate. Call scripts from the button OnClick() function. here you can add any of your scripts for the button to interact with.