JDK-4209844 : Modifiers not set for KEY_TYPED events on win32
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.8
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,windows_nt
  • CPU: generic
  • Submitted: 1999-02-08
  • Updated: 1999-07-20
  • Resolved: 1999-07-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other
1.1.8 1.1.8Fixed 1.2.2Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
This is a regression introduced in win32 JDK 1.1.8 build F.  The test case works fine on WinNT using 1.1.8 build E and 1.1.7B.  As far as I can tell, the test does not pass on Solaris for any 1.1 version of the JDK (see e.g. 4174399).

import java.awt.*;
import java.awt.event.*;

public class ModifierTest extends Frame implements KeyListener {

    public static void main(String args[]) {
        new ModifierTest();
    }

    public ModifierTest() {
        TextArea ta = new TextArea(8, 30);
        ta.addKeyListener(this);
        add(ta);
        pack();
        show();
    }

    public void keyPressed(KeyEvent evt)  { }
    public void keyReleased(KeyEvent e) { }

    public void keyTyped(KeyEvent evt)  {
        char keyChar = evt.getKeyChar();
        System.out.println("Key event = " + evt);
        System.out.println("Key mods  = " + KeyEvent.getKeyModifiersText(evt.get
Modifiers()));
        if ( evt.isShiftDown() ) {
            System.out.println("Shift key is down");
        }
        if ( evt.isControlDown()) {
            System.out.println("Control key is down");
        }
        if ( evt.isAltDown() ) {
            System.out.println("Alt key is down");
        }
        if ( evt.isMetaDown() ) {
            System.out.println("Meta key is down");
        }
    }

}

Example output from WinNT 4.0 SP3 when pressing Shift-A:

D:\KeyTest\reg>C:\jdk118F-bin\jdk1.1.8\bin\java -classpath C:\jdk118F-bin\jdk1.1
.8\lib\classes.zip;. ModifierTest
Key event = java.awt.event.KeyEvent[KEY_TYPED,keyCode=0,keyChar='A'] on text0
Key mods  =

D:\KeyTest\reg>C:\jdk118E-bin\jdk1.1.8\bin\java -classpath C:\jdk118E-bin\jdk1.1
.8\lib\classes.zip;. ModifierTest
Key event = java.awt.event.KeyEvent[KEY_TYPED,keyCode=0,keyChar='A',modifiers=Sh
ift] on text0
Key mods  = Shift
Shift key is down

stuart.lawrence@eng 1999-02-08

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.1.8 FIXED IN: 1.1.8 1.2.2 INTEGRATED IN: 1.1.8 1.2.2 VERIFIED IN: 1.1.8
14-06-2004

SUGGESTED FIX Name: vuC71690 Date: 03/04/99 ###@###.### 1999-03-04 For 1.1.8 *** /tmp/geta21707 Wed Feb 24 22:12:56 1999 --- awt_Component.cpp Wed Feb 24 21:39:02 1999 *************** *** 1413,1429 **** UINT message = system ? WM_SYSCHAR : WM_CHAR; WCHAR unicodeChar = L'\0'; - // Do NOT call GetJavaModifiers since Windows has already applied - // Ctrl/Shift modifiers to a key to translate it into a character. // The Alt modifier is reported in the 29th bit of the lParam, ! // which is the 13th bit of `flags' (which is a HIWORD(lParam)). ! // If this is a WM_SYSCHAR message, then we pass the Alt mask to ! // Java; if this is a WM_CHAR message, than Alt flag indicates ! // that the character was typed using an AltGr (== Ctrl+Alt), so ! // in this case we do NOT pass the Alt mask to Java (4122687). ! long modifiers = 0; ! if (system && (flags & (1<<13))) ! modifiers |= java_awt_Event_ALT_MASK; ::MultiByteToWideChar(GetCodePage(), 0, (TCHAR*)&character, 1, &unicodeChar, 1); --- 1413,1430 ---- UINT message = system ? WM_SYSCHAR : WM_CHAR; WCHAR unicodeChar = L'\0'; // The Alt modifier is reported in the 29th bit of the lParam, ! // i.e. is the 13th bit of `flags' (which is HIWORD(lParam)). If ! // this is a WM_CHAR (non system) message, than Alt flag indicates ! // that the character was typed using an AltGr key (which windows ! // treat as Ctrl+Alt), so in this case we do NOT pass the Alt and ! // Control modifiers to Java (4122687). ! long modifiers = GetJavaModifiers(flags, 0); ! if ((flags & (1<<13)) && !system) { // character typed with AltGr ! modifiers &= ~(java_awt_event_InputEvent_ALT_MASK ! | java_awt_event_InputEvent_CTRL_MASK); ! // In 1.2.x we also set ALT_GRAPH_MASK ! } ::MultiByteToWideChar(GetCodePage(), 0, (TCHAR*)&character, 1, &unicodeChar, 1); For 1.2.2 *** /tmp/geta21630 Wed Feb 24 21:36:23 1999 --- awt_Component.cpp Wed Feb 24 06:29:20 1999 *************** *** 1923,1939 **** // We will simply create Java events here. UINT message = system ? WM_SYSCHAR : WM_CHAR; - // Do NOT call GetJavaModifiers since Windows has already applied - // Ctrl/Shift modifiers to a key to translate it into a character. // The Alt modifier is reported in the 29th bit of the lParam, ! // which is the 13th bit of `flags' (which is a HIWORD(lParam)). ! // If this is a WM_SYSCHAR message, then we pass the Alt mask to ! // Java; if this is a WM_CHAR message, than Alt flag indicates ! // that the character was typed using an AltGr (== Ctrl+Alt), so ! // in this case we do NOT pass the Alt mask to Java. ! long modifiers = 0; ! if (system && (flags & (1<<13))) ! modifiers |= java_awt_Event_ALT_MASK; WCHAR unicodeChar = L'\0'; ::MultiByteToWideChar(GetCodePage(), 0, (TCHAR*)&character, 1, --- 1923,1941 ---- // We will simply create Java events here. UINT message = system ? WM_SYSCHAR : WM_CHAR; // The Alt modifier is reported in the 29th bit of the lParam, ! // i.e. is the 13th bit of `flags' (which is HIWORD(lParam)). If ! // this is a WM_CHAR (non system) message, than Alt flag indicates ! // that the character was typed using an AltGr key (which windows ! // treat as Ctrl+Alt), so in this case we do NOT pass the Alt and ! // Control modifiers to Java, but instead replace them with Java's ! // AltGraph modifer (4122687). ! long modifiers = GetJavaModifiers(flags, 0); ! if ((flags & (1<<13)) && !system) { // character typed with AltGr ! modifiers &= ~(java_awt_event_InputEvent_ALT_MASK ! | java_awt_event_InputEvent_CTRL_MASK); ! modifiers |= java_awt_event_InputEvent_ALT_GRAPH_MASK; ! } WCHAR unicodeChar = L'\0'; ::MultiByteToWideChar(GetCodePage(), 0, (TCHAR*)&character, 1, ======================================================================
11-06-2004

EVALUATION Needs to be fixed in 1.2.2 as well, since the same changes were made in that workspace. eric.hawkes@eng 1999-02-16 Test case is at /test/java/awt/event/KeyEvent/AltGrTest eric.hawkes@eng 1999-04-07
16-02-1999