简体   繁体   中英

Java Mouse Clicking Issue

Okay, so I created a pong game and it's cool and all but every time I go to the game I have to click on the window to use any controls. I was wondering if there is any way to be able to use the controls ( like wsad ) without having to click on the window. Just a question. Thanks if you answer and sorry that I can't vote you up because I don't got enough reputation.

KeyListener is well known for having focus related issues. This basically boils down to the fact that KeyListener will only respond to key presses if the component it is attached to is focusable and has focus.

Instead, you should try using the Key Bindings API which allows you to control the focus granuality, to the extent that so long as the window has focus, you can respond to key events (so long as some other component doesn't consume them first ;))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM