Key.ONE does not work with the JOGL renderer

Problems building or running Ardor3D, questions about how to use features, etc.

Key.ONE does not work with the JOGL renderer

Postby gouessej » Sun Dec 12, 2010 12:52 pm

Hi!

I want to use a KeyReleasedCondition on Key.ONE but it does not work, the trigger action is not called. If I replace this KeyReleasedCondition by another one using Key.NUMPAD1, it works. Is it a bug?
gouessej
regular
 
Posts: 1392
Joined: Fri May 01, 2009 3:26 am
Location: France

Re: Key.ONE does not work with the JOGL renderer

Postby gouessej » Mon Dec 13, 2010 5:37 am

I have just tested the Bloom demo. The LWJGL version works fine but I can use Key.ONE only when shift is pressed too. The JOGL version does not react when I press Key.ONE with or without shift. I'm going to fill a bug report right now.
gouessej
regular
 
Posts: 1392
Joined: Fri May 01, 2009 3:26 am
Location: France

Re: Key.ONE does not work with the JOGL renderer

Postby MrCoder » Mon Dec 13, 2010 6:04 am

Works perfectly for me in both lwjgl and jogl. What os are you on? (linux thing?)
Destroy, Erase, Improve
User avatar
MrCoder
Site Admin
 
Posts: 755
Joined: Mon Nov 03, 2008 8:56 am
Location: Stockholm, Sweden

Re: Key.ONE does not work with the JOGL renderer

Postby gouessej » Mon Dec 13, 2010 6:15 am

MrCoder wrote:Works perfectly for me in both lwjgl and jogl. What os are you on? (linux thing?)

I tested on Cent OS 5.3 and Mandriva Linux 2010. It seems to be an AWT bug. Please find below the key codes (KeyEvent.getKeyCode()) I get:
1: 150
2: 0
3: 152
4: 222
5: 519
6: 45
7: 0
8: 523
9: 0
0: 0
whereas all these codes should be between 48 and 57 (0x30 and 0x39). I use KDE 3 here and KDE 4 at home. It is not a bug of Ardor3D.

Edit.: it is reproducible only with non QWERTY keyboards whose numerical keys are used with accented or special letters. I'm going to try to fix it but I'm not sure using the Locale is enough to determine the keyboard layout.
gouessej
regular
 
Posts: 1392
Joined: Fri May 01, 2009 3:26 am
Location: France

Re: Key.ONE does not work with the JOGL renderer

Postby gouessej » Mon Dec 13, 2010 8:08 am

Please can you add the following keys into AwtKey?
VK_AMPERSAND
VK_QUOTEDBL
VK_LEFT_PARENTHESIS

You can see both QWERTY and AZERTY keyboards there:
http://www.informatique.math.jussieu.fr/public/documentation/fr/index.php/Chevaleret__Unix__Gamma__Softwares/Kbd-8bits

Which behavior would be fine according to you on platforms where VK_1 is never returned? Should VK_AMPERSAND match with Key.ONE (AZERTY) and Key.Seven (QWERTY)?

Edit.: that is why using the keys 0 to 9 is a bad idea:
(keyboard layout AZERTY, see Wikipedia)
The digits 0 to 9 are on the same keys, but to be typed the shift key must be pressed. The unshifted positions are used for accented characters
gouessej
regular
 
Posts: 1392
Joined: Fri May 01, 2009 3:26 am
Location: France

Re: Key.ONE does not work with the JOGL renderer

Postby renanse » Mon Dec 13, 2010 12:06 pm

It would be a bit of work, but I think ideally we would convert the demos to all use a HUD instead of various key presses.

gouessej wrote:Please can you add the following keys into AwtKey?
VK_AMPERSAND
VK_QUOTEDBL
VK_LEFT_PARENTHESIS

I'll take a look at these.
Gratitude is a mark of a noble soul and a refined character.
User avatar
renanse
Site Admin
 
Posts: 2988
Joined: Tue Oct 28, 2008 6:49 pm
Location: Austin, TX

Re: Key.ONE does not work with the JOGL renderer

Postby gouessej » Mon Dec 13, 2010 12:48 pm

I can detect the keyboard layout by using the default locale but AwtKey only passes the KeyEvent constant that is not enough. I'm going to provide a patch to work around this "limitation" of Java.
gouessej
regular
 
Posts: 1392
Joined: Fri May 01, 2009 3:26 am
Location: France

Re: Key.ONE does not work with the JOGL renderer

Postby gouessej » Mon Dec 13, 2010 2:10 pm

My patch is below. Let me know what you think about it. If you don't like it, I will have to implement a small workaround in my own code.


### Eclipse Workspace Patch 1.0
#P ardor3d-awt
Index: src/main/java/com/ardor3d/input/awt/AwtKeyboardWrapper.java
===================================================================
--- src/main/java/com/ardor3d/input/awt/AwtKeyboardWrapper.java (revision 1497)
+++ src/main/java/com/ardor3d/input/awt/AwtKeyboardWrapper.java (working copy)
@@ -40,7 +40,6 @@

private final EnumSet<Key> _pressedList = EnumSet.noneOf(Key.class);

-
public AwtKeyboardWrapper(final Component component) {
_component = Preconditions.checkNotNull(component, "component");
}
@@ -65,11 +64,11 @@
}

public synchronized void keyTyped(final java.awt.event.KeyEvent e) {
- // ignore this event
+ // ignore this event
}

public synchronized void keyPressed(final java.awt.event.KeyEvent e) {
- final Key pressed = AwtKey.findByCode(e.getKeyCode());
+ final Key pressed = AwtKey.findByCode(e.getKeyCode(), e.getKeyChar());
if (!_pressedList.contains(pressed)) {
_upcomingEvents.add(new KeyEvent(pressed, KeyState.DOWN, e.getKeyChar()));
_pressedList.add(pressed);
@@ -77,7 +76,7 @@
}

public synchronized void keyReleased(final java.awt.event.KeyEvent e) {
- final Key released = AwtKey.findByCode(e.getKeyCode());
+ final Key released = AwtKey.findByCode(e.getKeyCode(), e.getKeyChar());
_upcomingEvents.add(new KeyEvent(released, KeyState.UP, e.getKeyChar()));
_pressedList.remove(released);
}
Index: src/main/java/com/ardor3d/input/awt/AwtKey.java
===================================================================
--- src/main/java/com/ardor3d/input/awt/AwtKey.java (revision 1497)
+++ src/main/java/com/ardor3d/input/awt/AwtKey.java (working copy)
@@ -11,6 +11,7 @@
package com.ardor3d.input.awt;

import java.awt.event.KeyEvent;
+import java.util.Locale;

import com.ardor3d.input.Key;

@@ -138,13 +139,78 @@
_key = key;
}

- public static Key findByCode(final int awtCode) {
+ public static Key findByCode(final int awtCode, final char awtKeyChar) {
+ final Locale defaultLocale = Locale.getDefault();
+ final String country = defaultLocale.getCountry();
+ if (defaultLocale.getLanguage().equals("fr") && (country.equals("FR") || country.equals("BE"))) {
+ switch (awtKeyChar) {
+ case '1':
+ if (awtCode == KeyEvent.VK_AMPERSAND) {
+ return Key.ONE;
+ }
+ case '&':
+ return Key.ONE;
+ case '2':
+ if (awtCode == KeyEvent.VK_UNDEFINED) {
+ return Key.TWO;
+ }
+ case 'é':
+ return Key.TWO;
+ case '3':
+ if (awtCode == KeyEvent.VK_QUOTEDBL) {
+ return Key.THREE;
+ }
+ case '\"':
+ return Key.THREE;
+ case '4':
+ if (awtCode == KeyEvent.VK_QUOTE) {
+ return Key.FOUR;
+ }
+ case '\'':
+ return Key.FOUR;
+ case '5':
+ if (awtCode == KeyEvent.VK_LEFT_PARENTHESIS) {
+ return Key.FIVE;
+ }
+ case '(':
+ return Key.FIVE;
+ case '6':
+ if (awtCode == KeyEvent.VK_MINUS) {
+ return Key.SIX;
+ }
+ case '-':
+ return Key.SIX;
+ case '7':
+ if (awtCode == KeyEvent.VK_UNDEFINED) {
+ return Key.SEVEN;
+ }
+ case 'è':
+ return Key.SEVEN;
+ case '8':
+ if (awtCode == KeyEvent.VK_UNDERSCORE) {
+ return Key.EIGHT;
+ }
+ case '_':
+ return Key.EIGHT;
+ case '9':
+ if (awtCode == KeyEvent.VK_UNDEFINED) {
+ return Key.NINE;
+ }
+ case 'ç':
+ return Key.NINE;
+ case '0':
+ if (awtCode == KeyEvent.VK_UNDEFINED) {
+ return Key.ZERO;
+ }
+ case 'à':
+ return Key.ZERO;
+ }
+ }
for (final AwtKey ak : values()) {
if (ak._awtCode == awtCode) {
return ak._key;
}
}
-
return Key.UNKNOWN;
}
gouessej
regular
 
Posts: 1392
Joined: Fri May 01, 2009 3:26 am
Location: France

Re: Key.ONE does not work with the JOGL renderer

Postby renanse » Mon Dec 13, 2010 2:24 pm

Hmm, is there a way to do this where we can plug in the differences by country? I'd rather not have to explicitly support region in this way. Locale.getDefault() may not mean you have a matching keyboard for example...
Gratitude is a mark of a noble soul and a refined character.
User avatar
renanse
Site Admin
 
Posts: 2988
Joined: Tue Oct 28, 2008 6:49 pm
Location: Austin, TX

Re: Key.ONE does not work with the JOGL renderer

Postby gouessej » Mon Dec 13, 2010 4:01 pm

renanse wrote:Hmm, is there a way to do this where we can plug in the differences by country? I'd rather not have to explicitly support region in this way.

Why not? What do you mean exactly? Keep in mind that this "bug" concerns exclusively the AZERTY keyboards and its derived versions whereas most of the keyboards in the world are derived from QWERTY.

renanse wrote:Locale.getDefault() may not mean you have a matching keyboard for example...

It is not the case only if the user changes its keyboard layout without rebooting while using your application. If I change my keyboard layout, $LANG will be modified and after a reboot, Locale.getDefault() is different too (fr_US.UTF8 for example). InputContext.getInstance().getLocale() might be a bit more accurate.

Edit.: I had forgotten "else {break;}" several times in the fix...
gouessej
regular
 
Posts: 1392
Joined: Fri May 01, 2009 3:26 am
Location: France

Next

Return to HELP!

Who is online

Users browsing this forum: No registered users and 3 guests

cron