Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4177788
Votes 3
Synopsis Inconsistent mapping of modifier keys a problem with Swing
Category java:classes_awt
Reported Against 1.1.7 , 1.2.1
Release Fixed 1.4(merlin-beta)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs 1240516
Submit Date 30-SEP-1998
Description



=20
/*
(1)
Depending on how the modifier keys are mapped in
X-Windows, java applications with hot-keys or
mnemonics may not work.

On Solaris, set your X-windows modifier mapping
by running the commands (in a shell):
xmodmap -e 'clear mod1' -e 'clear mod4'
xmodmap -e 'add mod1 =3D Meta_L Meta_R'
xmodmap -e 'add mod4 =3D Alt_L'

(This mapping of the Alt and Meta keys are not
unusual -> Java is not platform independent unless
this is correctly handled.)

Compile and run the attached java code. Note that
pressing any of the Meta keys is regarded by the
program as Meta+Alt, whereas pressing the Alt key
isn't recognized as a modifier key.

Try, also, to run a Swing application with
mnemonics, such as SwingSet. You won't be able to
use the mnemonics.

Now, change your X-windows modifier mapping by
running these commands:
xmodmap -e 'clear mod1' -e 'clear mod4'
xmodmap -e 'add mod1 =3D Alt_L'
xmodmap -e 'add mod4 =3D Meta_L Meta_R'

If you test the same java program with this
modifier mapping, you will get a correct
interpretation of the modifier keys.

This indicates that, keys mapped to mod1 are
assumed to be Alt modifiers, but the keys named
Meta_L and Meta_R are assumed to be Meta modifiers.

A working solution would obviously be to completely
ignore the X-Windows modifier mapping and just
map the key named Alt_L to Alt (just the way it
is done with the Meta_L and Meta_R keys).

(2)
*/
import java.awt.*;
import java.awt.event.*;

public class ModifierTest extends Frame implements KeyListener {
    public ModifierTest() {
        addWindowListener(new WindowAdapter() {=20
            public void windowClosing(WindowEvent e) { System.exit(0); }
        });
        addKeyListener(this);
        setSize(100, 100);
    }
 =20
    public void keyPressed(KeyEvent e){
        System.out.println(e);
    }

    public void keyReleased(KeyEvent e){
        System.out.println(e);
    }

    public void keyTyped(KeyEvent e){
        System.out.println(e);
    }

    public static void main(String[] args){
        Frame f =3D new ModifierTest();
        f.show();
    }
}

(Review ID: 39711)
======================================================================
Work Around



=20
Implement the control for Alt modifiers the same
way as Meta modifiers.
======================================================================
Evaluation



  xxxxx@xxxxx  

Depending on how the modifier keys are mapped in X-Windows, java may
indicate wrong modifiers of the event. It seems that java interprets
modifier keys with built-in default modifier map and do not get into
account the system settings or wrongly interprets modifier keys
"mixing" them.

Examining the code it can be seen that AWT have hard coded
modifier map for several modifier keys. This is the reason of
nonsensetivity of java for changing system modifier map.

Another issue is if there are some modifier keys are missed on user
system (they have no keycode) then the modifier masks for them will
eventually appear in modifiers set of the event in java. It is because
of establishing of wrong equality by checking of the keycodes for such
a keys, which are zero, with keycodes in the system modifier map,
which also can be zero.


======================================================================
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang