Key Input by script

Hi. I have a question.

Can I input the key by script?

I want to make script to input left arrow key.

plz someone help me.

Check these links out:

Input docs

Input.GetKeyDown

KeyCode

Example:

if(Input.GetKeyDown(KeyCode.LeftArrow))
     //left arrow key has been pressed!

PS: Next time you ask a question, please, google it first. http://lmgtfy.com/?q=Unity+Key+Input+by+script or you won’t get an answer.

–David–

Those links refer to tracking user input

After years the question stands (after a complete reading and several days of diligent struggle over this issue)

can we create “user” key input via script?

I don’t know if you can simulate a key input outright, but I don’t think you ever really need to?


Instead of doing

if (Input.GetKeyDown(keycode)) { /*do_code*/ }

Just use

if (Input.GetKeyDown(keycode))
    keyDown = true;
if (keyDown) { /*do_code*/ }
keyDown = false;

If you then set the keyDown variable to true manually, this basically simulates a key press.


…Which is probably what OP ended up doing since the question is super-duper old; I’m more answering for @BryanO up there.