This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Game Development and the fly likes Arrow for direction, Shift for run Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Arrow for direction, Shift for run" Watch "Arrow for direction, Shift for run" New topic
Author

Arrow for direction, Shift for run

Ben Watt
Greenhorn

Joined: Feb 13, 2009
Posts: 8
Is there way to have 2 keys being pressed at the same time and be able to have the prior action along with it?

I know that if you press down both keys at the same time, the effect will occur.

But I want to be able to walk a direction for an amount of time, then press and hold down the Shift key and have the character start running.



Any help?


All we are, are just zeros and ones
Paul Beckett
Ranch Hand

Joined: Jun 14, 2008
Posts: 96
KeyEvent has an isShiftDown() method.

does that help?

Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
Couldn't you add an action for Detect_Initial_Press_Only for the Shift key that increases your speed and then On_Key_Release decrese the speed back to a walking speed? OR

While Shift.isPressed() speed = RUN_SPEED otherwise speed = WALK_SPEED

I would try one of those as a work around, I have never actually tried to detect multiple keys being pressed at once and have them both firing off actions. I'm sure it's possible though, fighting games seem to be all about multi-button mashing. Let us know if you can't get anything working and I'll try and play with some code to experiment.


SCJA
~Currently preparing for SCJP6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arrow for direction, Shift for run
 
Similar Threads
Bit Shifting
Any plans for SDK release on Windows or Linux computers? Java Support?
Java KeyListener - can't detect multiple pressed buttons
Key Press Pressure / Typing Pressure software
Can't do multiple selections