Input.GetKeyDown doesn't work when I click an object or other parts

Input.GetKeyDown works when I hit the keyboard without clicking any other part on the screen after I hit play. However, it doesn’t work whenever I click an object or other parts of the screen, such as console or hierarchy. I don’t think there’s an error with the script I wrote because the same thing happened when I wrote a new simple code using Input.GetKeyDown to test if there’s an error with the script. Does anyone know why?

:P, because you are not “in the game” its like alt tab ing. can you imaging if the game would play in the background while you are like coding :stuck_out_tongue:

Edit: i should have explained this better, The game window/tab is “like in the game” so when you click out side for example the editor window, you are now in the unity editor so any key press our mouse will happen in the editor. if you now click back on the Game window, now you are in the game and any key or mouse inputs will happen in the game.

Game has to be in an active tab. Try clicking on the “game” tab and try pressing the button on your keyboard again.

You can also try checking “Run In Background” in player settings.

If that doesn’t work, maybe show us your code, you may somehow disable the component with GetKeyDown by accident (or some other weird stuff may happen)