Bug 631 - NEWT keyReleased event abnormal behaviour.
Summary: NEWT keyReleased event abnormal behaviour.
Status: RESOLVED FIXED
Alias: None
Product: Newt
Classification: JogAmp
Component: core (show other bugs)
Version: 1
Hardware: pc_x86_64 all
: --- critical
Assignee: Sven Gothel
URL:
Depends on:
Blocks:
 
Reported: 2012-10-25 04:00 CEST by leigh beattie
Modified: 2012-10-28 04:20 CET (History)
3 users (show)

See Also:
Type: ---
SCM Refs:
jogl 2f9c77a347b76bebdadd4bec1ac92aa7ab72365f
Workaround: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description leigh beattie 2012-10-25 04:00:13 CEST
I'm building a game with jogl which runs fine on my Windows and Linux PC, which uses the latest stable jogl version. However on Mac I need to use the autobuilds to get GL3.2 support, and the keypress behaviour breaks. 

I have a listener that both handles keyPressed and keyReleased events and sets state. The problem is if I hold two keys down, say W and D for forward and strafe right and I release both of them then the one I pressed first becomes "stuck". as in it doesn't fire it's keyreleased event. It seems to depend on how long I hold the keys, how slowly I release them, it's very inconsistent.

Also, for a key like W the keycode for the key pressed is 83 however while it's held down it reports that key 13 is being released and when I finally actually release it keycode 83 is reported as being released.

This is critical as flying a space ship is hard when the left or forward key is stuck in the "pressed" state.

@Override
	public void keyPressed(KeyEvent arg0) {
		System.out.println("KeyPressed! : " + arg0.getKeyCode());
		switch(arg0.getKeyCode()){
		case FORWARD:
			shipEvent.setAction(ShipControlEvent.ACTION_FORWARD);
			shipEvent.setStatus(ShipControlEvent.STATUS_START);
			Renderer.eventDaemon.fireEvent(shipEvent.getEventName(), shipEvent);
			break;
		case BACKWARD:
			shipEvent.setAction(ShipControlEvent.ACTION_BACKWARD);
			shipEvent.setStatus(ShipControlEvent.STATUS_START);
			Renderer.eventDaemon.fireEvent(shipEvent.getEventName(), shipEvent);
			break;
		case STRAFE_LEFT:
			shipEvent.setAction(ShipControlEvent.ACTION_TURN_LEFT);
			shipEvent.setStatus(ShipControlEvent.STATUS_START);
			Renderer.eventDaemon.fireEvent(shipEvent.getEventName(), shipEvent);
			break;
		case STRAFE_RIGHT:
			shipEvent.setAction(ShipControlEvent.ACTION_TURN_RIGHT);
			shipEvent.setStatus(ShipControlEvent.STATUS_START);
			Renderer.eventDaemon.fireEvent(shipEvent.getEventName(), shipEvent);
			break;
		case SPRINT:
			shipEvent.setAction(ShipControlEvent.ACTION_SPRINT);
			shipEvent.setStatus(ShipControlEvent.STATUS_START);
			Renderer.eventDaemon.fireEvent(shipEvent.getEventName(), shipEvent);
			break;
		}
	}

	@Override
	public void keyReleased(KeyEvent arg0) {

		System.out.println("KeyReleased! : " + arg0.getKeyCode());
			switch(arg0.getKeyCode()){
			case FORWARD:
				shipEvent.setAction(ShipControlEvent.ACTION_FORWARD);
				shipEvent.setStatus(ShipControlEvent.STATUS_STOP);
				Renderer.eventDaemon.fireEvent(shipEvent.getEventName(), shipEvent);
				break;
			case BACKWARD:
				shipEvent.setAction(ShipControlEvent.ACTION_BACKWARD);
				shipEvent.setStatus(ShipControlEvent.STATUS_STOP);
				Renderer.eventDaemon.fireEvent(shipEvent.getEventName(), shipEvent);
				break;
			case STRAFE_LEFT:
				shipEvent.setAction(ShipControlEvent.ACTION_TURN_LEFT);
				shipEvent.setStatus(ShipControlEvent.STATUS_STOP);
				Renderer.eventDaemon.fireEvent(shipEvent.getEventName(), shipEvent);
				break;
			case STRAFE_RIGHT:
				shipEvent.setAction(ShipControlEvent.ACTION_TURN_RIGHT);
				shipEvent.setStatus(ShipControlEvent.STATUS_STOP);
				Renderer.eventDaemon.fireEvent(shipEvent.getEventName(), shipEvent);
				break;
			case SPRINT:
				shipEvent.setAction(ShipControlEvent.ACTION_SPRINT);
				shipEvent.setStatus(ShipControlEvent.STATUS_STOP);
				Renderer.eventDaemon.fireEvent(shipEvent.getEventName(), shipEvent);
				break;
			}
		//}
	}
Comment 1 Sven Gothel 2012-10-26 16:51:13 CEST
Does multiple key press/release work on:
  - Linux/X11
  - Windows 
?
This is not quite clears, since it would be possible you tested this w/ an older version.

Can you check Bug 601 (not quite related .. but touches the issue a bit)
and use one of the new unit tests as a template to create a new one
reproducing the erroneous behavior ?
  http://jogamp.org/git/?p=jogl.git;a=commit;h=b008de41549e38aebdfcb7b094046235a8dde72f

This would really help a lot in fixing it.

Thank you.
Comment 2 Sven Gothel 2012-10-27 02:51:45 CEST
Enhanced w/ multiple key support, see:
  <http://jogamp.org/git/?p=jogl.git;a=commit;h=2f9c77a347b76bebdadd4bec1ac92aa7ab72365f>
Comment 3 leigh beattie 2012-10-28 04:20:46 CET
Pulled latest repo, confirmed fixed! Thank you so much :D