NEWT KeyEvents behaving odd in Linux

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

NEWT KeyEvents behaving odd in Linux

maxs
Hey guys,

Love JOGL, thanks for your work on it.

I've got a problem using NEWT on Linux (Ubuntu 12.04).  I've created a GLWindow using:

    final GLProfile profile = GLProfile.get(GLProfile.GL2ES2);
    final GLCapabilities capabilities = new GLCapabilities(profile);
    gameWindow = GLWindow.create(capabilities);

However, I noticed something was odd with the KeyEvents.  I added a TraceKeyListener to investigate:

    gameWindow.addKeyListener(new TraceKeyAdapter());

And here is the output when I hold the key 'b' for a while without releasing:

KeyEvent[EVENT_KEY_PRESSED, code 66(0x42), char '?' (0xffff), isActionKey false, InputEvent[modifiers: 0x0, NEWTEvent[sys:false, source:jogamp.newt.driver.x11.X11Window, when:1338354727112 d 0ms]]]
KeyEvent[EVENT_KEY_RELEASED, code 66(0x42), char '?' (0xffff), isActionKey false, InputEvent[modifiers: 0x0, NEWTEvent[sys:false, source:jogamp.newt.driver.x11.X11Window, when:1338354727617 d 0ms]]]
KeyEvent[EVENT_KEY_TYPED, code 66(0x42), char 'b' (0x62), isActionKey false, InputEvent[modifiers: 0x0, NEWTEvent[sys:false, source:jogamp.newt.driver.x11.X11Window, when:1338354727617 d 0ms]]]
KeyEvent[EVENT_KEY_PRESSED, code 66(0x42), char '?' (0xffff), isActionKey false, InputEvent[modifiers: 0x0, NEWTEvent[sys:false, source:jogamp.newt.driver.x11.X11Window, when:1338354727618 d 0ms]]]
KeyEvent[EVENT_KEY_RELEASED, code 66(0x42), char '?' (0xffff), isActionKey false, InputEvent[modifiers: 0x0, NEWTEvent[sys:false, source:jogamp.newt.driver.x11.X11Window, when:1338354727638 d 1ms]]]
KeyEvent[EVENT_KEY_TYPED, code 66(0x42), char 'b' (0x62), isActionKey false, InputEvent[modifiers: 0x0, NEWTEvent[sys:false, source:jogamp.newt.driver.x11.X11Window, when:1338354727639 d 0ms]]]
KeyEvent[EVENT_KEY_PRESSED, code 66(0x42), char '?' (0xffff), isActionKey false, InputEvent[modifiers: 0x0, NEWTEvent[sys:false, source:jogamp.newt.driver.x11.X11Window, when:1338354727639 d 0ms]]]
KeyEvent[EVENT_KEY_RELEASED, code 66(0x42), char '?' (0xffff), isActionKey false, InputEvent[modifiers: 0x0, NEWTEvent[sys:false, source:jogamp.newt.driver.x11.X11Window, when:1338354727670 d 0ms]]]
KeyEvent[EVENT_KEY_TYPED, code 66(0x42), char 'b' (0x62), isActionKey false, InputEvent[modifiers: 0x0, NEWTEvent[sys:false, source:jogamp.newt.driver.x11.X11Window, when:1338354727671 d 0ms]]]
KeyEvent[EVENT_KEY_PRESSED, code 66(0x42), char '?' (0xffff), isActionKey false, InputEvent[modifiers: 0x0, NEWTEvent[sys:false, source:jogamp.newt.driver.x11.X11Window, when:1338354727671 d 0ms]]]
KeyEvent[EVENT_KEY_RELEASED, code 66(0x42), char '?' (0xffff), isActionKey false, InputEvent[modifiers: 0x0, NEWTEvent[sys:false, source:jogamp.newt.driver.x11.X11Window, when:1338354727682 d 0ms]]]
KeyEvent[EVENT_KEY_TYPED, code 66(0x42), char 'b' (0x62), isActionKey false, InputEvent[modifiers: 0x0, NEWTEvent[sys:false, source:jogamp.newt.driver.x11.X11Window, when:1338354727682 d 0ms]]]
FPS = 58
KeyEvent[EVENT_KEY_PRESSED, code 66(0x42), char '?' (0xffff), isActionKey false, InputEvent[modifiers: 0x0, NEWTEvent[sys:false, source:jogamp.newt.driver.x11.X11Window, when:1338354728608 d 0ms]]]
KeyEvent[EVENT_KEY_RELEASED, code 66(0x42), char '?' (0xffff), isActionKey false, InputEvent[modifiers: 0x0, NEWTEvent[sys:false, source:jogamp.newt.driver.x11.X11Window, when:1338354728933 d 0ms]]]
KeyEvent[EVENT_KEY_TYPED, code 66(0x42), char 'b' (0x62), isActionKey false, InputEvent[modifiers: 0x0, NEWTEvent[sys:false, source:jogamp.newt.driver.x11.X11Window, when:1338354728934 d 0ms]]]

To clarify: I am holding 'b' down, but I am getting consecutive Pressed/Released/Typed events.  I'd instead expect to get only one set of Pressed/Released events (I am not sure what Typed event is).   I am also confused about the char 0xffff events -- what's going on here?

Thank you very much for any help!

--
Max
Reply | Threaded
Open this post in threaded view
|

Re: NEWT KeyEvents behaving odd in Linux

gouessej
Administrator
Hi

It's not that strange, AWT has the same behavior under GNU Linux, it is explained in the Java documentation of the class java.awt.KeyEvent. This behavior is not the same than under Windows. Maybe try to disable auto-repeat (look at the man of xset).

Edit.: a potential "fix" can be found here:
http://tech.stolsvik.com/2010/05/linux-java-repeats-released-keyevents.html
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: NEWT KeyEvents behaving odd in Linux

gouessej
Administrator
In reply to this post by maxs
Actually, we should write a bug report about this problem. The useless "release" key events are generated in the native level by the operating system. We should be able to disable/enable auto-repeat. If you really want to do that, you can use my source code, I use a shell command to disable auto-repeat. You have to use a shutdown hook to reenable it when leaving the applications if necessary. Thank you for pointing that. Actually, auto-repeat is no more enabled by default on my distro (Mageia Linux 1) whereas it was enabled in the previous one (Mandriva Linux). Maybe such a modifier should not be in NEWT as it would affect AWT too.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: NEWT KeyEvents behaving odd in Linux

maxs
Dear Julien,

Thank you for your response.  You are welcome to post a bug report, but I'd like to first take a peek at the source code.  Maybe we can find a solution that would work.  I'm busy on Thursday, but I can look into it on Friday.

I think this is a major problem for Linux games with NEWT.  Xset is a solution, but it means that you can't just distribute the game as a jar.  Do you maybe know if jinput can be used for the keyboard with NEWT?  That would be an alternative, though I'd rather have NEWT "fixed" :)

All the best,
Max
Reply | Threaded
Open this post in threaded view
|

Re: NEWT KeyEvents behaving odd in Linux

Sven Gothel
Administrator
On 05/31/2012 06:25 AM, maxs [via jogamp] wrote:

> Dear Julien,
>
> Thank you for your response.  You are welcome to post a bug report, but I'd
> like to first take a peek at the source code.  Maybe we can find a solution
> that would work.  I'm busy on Thursday, but I can look into it on Friday.
>
> I think this is a major problem for Linux games with NEWT.  Xset is a
> solution, but it means that you can't just distribute the game as a jar.  Do
> you maybe know if jinput can be used for the keyboard with NEWT?  That would
> be an alternative, though I'd rather have NEWT "fixed" :)
Which means we need the bugreport/fix, so NEWT may override the X11
autorepeat [optionally].

~Sven


signature.asc (910 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: NEWT KeyEvents behaving odd in Linux

gouessej
Administrator
In reply to this post by maxs
I checked that yesterday, it is not a problem in my first person shooter because the main author (Renanse) of the engine (Ardor3D) knows this behavior and the NEWT part I added uses a similar code to avoid bothering me with useless key release events. I can update my demo if you want to check that.

xset is a bad solution and I used it badly, I always (re)enabled the auto-repeat even when it was not previously enabled.

NEVER DISTRIBUTE A GAME AS A SINGLE JAR. I'm sorry to repeat that once again but this is a very bad way of deploying a game, any archiver (WinRAR, Arch) may open the JAR instead of Java, the final user won't understand what is happening and will complain. I advise you to use Java Wet Start (a bit buggy but I know how to work around its main bugs or broken features, very simple, very complete), GetDown (stable, used by a few commercial games but a bit complicated) or IzPack (stable but quite complicated and some major features are missing).

We plan to ease the use of JInput with JogAmp, this minimal fork is "JInput for JogAmp". Using JInput and NEWT is not contradictory. Anyway, I assume JInput doesn't "fix" this "bug" as it uses the native events.

Microsoft Windows does that when you press and release a key:
pressed key event
pressed key event
pressed key event
pressed key event
released key event
typed key event

In games, we often just want to get that:
pressed key event
released key event
typed key event

In my humble opinion, tinkering key events is almost always necessary when writing games. Neither the default behavior under Windows nor the default behavior under Linux with auto-repeat enabled is satisfying. We could modify NEWT in order to avoid getting these events but it would be bothering for people who rely on auto-repeat and who port a program from AWT to NEWT.

Qt solution is interesting, a key event generated by the auto-repeat is marked so that you can skip it easily. I want to avoid suggesting a solution that would affect the whole operating system and not only our applications. XAutoRepeatOff or XkbSetDetectableAutorepeat affects the whole session.

The best idea I have found is this one:
http://stackoverflow.com/posts/3220822/revisions

We have two choices to solve our problem:
- flag auto-repeat events in the native part of NEWT
- add an option into NEWT that would allow to enable or disable auto-repeat for a particular application

Both could be implemented too. What's your opinion about that?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: NEWT KeyEvents behaving odd in Linux

gouessej
Administrator
In reply to this post by Sven Gothel
Sven, it seems not possible to override this behavior only for a Java application by using X11 API, a change of setting affects at least the whole session or the whole X11 options. It is not a problem for a game but it is a limitation for applications.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: NEWT KeyEvents behaving odd in Linux

gouessej
Administrator
In reply to this post by maxs
Hi

I have just written a bug report about that:
https://jogamp.org/bugzilla/show_bug.cgi?id=601
Julien Gouesse | Personal blog | Website