aspose file tools*
The moose likes Game Development and the fly likes Problem with multiple keys pressed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Problem with multiple keys pressed" Watch "Problem with multiple keys pressed" New topic
Author

Problem with multiple keys pressed

Kalman Aldridge
Greenhorn

Joined: Mar 01, 2011
Posts: 3
I'm having an issue with some code I'm just playing around with. Imagine a top down space shooter. The issue I'm having is that, on my computer, when I press and hold the up and left arrows, I cannot shoot (Spacebar). Any other direction (up, down, left, right, up + right, right + down, left + down) works. I had a friend run the code on his computer and he found that all directions worked except up + right and right + down, but up + left worked fine for him. We both looked at the code and can't figure it out. Could this be a hardware issue?

Basically, this is what I'm doing:

Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

Yes, I believe it's actually a keyboard limitation. Try running on the same computer with a different keyboard.
tom klu
Greenhorn

Joined: Mar 04, 2011
Posts: 2
well, i think you should try this:

i use a whole different method , but i prefer this one
post this in your keypressed method be sure to make it KeyEvent e


be sure to copy this code also in the keyreleased, set the booleans to false.
you might ask UP,DOWN,LEFT,RIGHT?
just add this in your script:
Niall Watchorn
Greenhorn

Joined: Mar 01, 2011
Posts: 2


Timer timer = new Timer(250, new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (up)
System.out.println("Moving UP.");
if (left)
System.out.println("Moving LEFT.");
if (right)
System.out.println("Moving RIGHT.");
if (down)
System.out.println("Moving DOWN.");
if (fire)
{
System.out.println("FIRING.");
fire = false;
}
}
});



Also, you are missing a bracket and ; on line 109 I think it is, they are actually on line 119, dunno if that's just an upload error or if it's coded like that.

Niall
Kalman Aldridge
Greenhorn

Joined: Mar 01, 2011
Posts: 3
tom klu wrote:well, i think you should try this:

i use a whole different method , but i prefer this one
post this in your keypressed method be sure to make it KeyEvent e


be sure to copy this code also in the keyreleased, set the booleans to false.
you might ask UP,DOWN,LEFT,RIGHT?
just add this in your script:


I tried your code but I still had the same issue. What's the preferred method to handle this in games? Surely there must be a solution.
tom klu
Greenhorn

Joined: Mar 04, 2011
Posts: 2
well you might try making booleans..... this will def. work or otherwise it must be your keyboard.
Kalman Aldridge
Greenhorn

Joined: Mar 01, 2011
Posts: 3
Stephan van Hulst wrote:Yes, I believe it's actually a keyboard limitation. Try running on the same computer with a different keyboard.


I did try a different keyboard but had the same results. The same key combination did not work.

tom klu wrote:well you might try making booleans..... this will def. work or otherwise it must be your keyboard.


I downloaded a top down space shooter programmed in Java and had no issues moving up and left and firing. However, movement used WASD instead of the arrow keys - as does your code above. It now works using WASD so it must be an issue with using the arrow keys and spacebar at the same time.
 
Don't get me started about those stupid light bulbs.
 
subject: Problem with multiple keys pressed