Mac First wrote:
On my Intel/Leopard system, I get this:
[Session started at 2008-01-25 18:50:00 -0800.]
Pigs!
type : 401 // (401 = keydown)
code: 32
text: ? // <space>
type : 400 // 400 = key-repeat? Key-typed? Whatever...
code: 0
text: Unknown keyCode: 0x0
type : 402 // (402 = keyup)
code: 32
text: ?
type : 401
code: 37 // left arrow
text: ?
type : 402
code: 37
text: ?
type : 401
code: 39 // right arrow
The ResourceBundle for "sun.awt.resources.awt" appears to be screwy
under
Java 1.5, but fine under 1.4.2, both on Leopard. It's also fine
under 1.5
or 1.4.2 on 10.4.9.
Test program:
- - - - -
// This code released into the public domain.
// AS-IS, WITHOUT WARRANTY.
import java.awt.event.*;
import java.util.*;
public class KeyTexts
{
public static void main( String[] args )
{
show( 27 );
show( 37 );
show( 20 );
show( 909 ); // illegal/unknown
ResourceBundle bundle = null;
try
{ bundle = ResourceBundle.getBundle( "sun.awt.resources.awt" ); }
catch ( Exception ignored )
{ ; }
System.out.println( "bundle = " + bundle );
}
private static void show( int code )
{ System.out.println( "code: " + code
+ ", text: " + KeyEvent.getKeyText( code ) ); }
}
- - - - -
To understand what it's testing and the significance of that
ResourceBundle, look at the source of
java.awt.Toolkit.getProperty(), and
Toolkit's static initializer for the 'resources' field. Also see
source of
KeyEvent.getKeyText() for how Toolkit.getProperty() gets in.
I'm afraid I don't know of a fix. Maybe use reflection to set the
'resources' static field in Toolkit to null, but I'm not sure of all
the
consequences. Alternatively, set the right property or config-value
so the
ResourceBundle.getBundle() refers to something correct instead of
screwy.
Definitely file a bug, because this ought to work.
<http://developer.apple.com/bugreporter>
Feel free to use the above code to demonstrate the problem.