I must click my window before interacting with my game

I have a simple game, and when I launch the program, I have to click on the window before the game accepts user input.

When I play games like The Binding of Isaac they accept user input on the main menu without me ever clicking on them.

Is there a way to adjust my keyboard focus to my game without clicking first? There was one more question: You need to press before pressing the key , but it remained unanswered.

+3


source to share


2 answers


Calling window.requestFocus (); after calling main.start () so that you override any other focus request made in the meantime



+1


source


If you have JFrame

or something like this (something inherited from java.awt.Component

) you can try:

window.requestFocus();

      

Link to javadoc




EDIT:
In case JFrame

, I found this question:
How to focus a JFrame? One answer is the same as the advice. This might help you
+1


source







All Articles