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: 4744373
Votes 0
Synopsis Toolkit.getLockingKeyState() does not return Scroll lock state
Category java:classes_awt
Reported Against 1.4
Release Fixed
State 6-Fix Understood, bug
Priority: 4-Low
Related Bugs 4757896 , 6446665 , 4414164
Submit Date 10-SEP-2002
Description
java version "1.4.1-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b19)
Java HotSpot(TM) Client VM (build 1.4.1-rc-b19, mixed mode)

Calling toolkit.getLockingKeyState(KeyEvent.VK_SCROLL_LOCK) always returns whether the scroll lock key is currently held down, instead of current state of Scroll Lock.

Try running following sample program; every second it prints the scroll lock state.Try pressing Scroll lock; not that getLockingKeyState only returns true if you are holding scroll lock while it is called, if you press caps lock once (to enable it and release, then you get false back.

import java.awt.Toolkit;
import java.awt.event.KeyEvent;

public class ScrollProb {
  public static void main(String args[]) {
    for (;;) {
      try {
	Thread.sleep(1000);
      } catch(InterruptedException excep) {}
      System.out.println("Scroll lock on? " +
			 Toolkit.getDefaultToolkit().getLockingKeyState(
			   KeyEvent.VK_SCROLL_LOCK));
    }
  }
}
Work Around
N/A
Evaluation
Commit to fix in tiger.  
  xxxxx@xxxxx   2002-09-09

-----------------------------------------------
XQueryKeymap() is the method, Java is using to get the status of keys on Keyboard. 

I wrote a simple "C" testcase which uses XQueryKeymap() method to get the current status of keys on the keyboard. It returns 32 bytes, each bit representing the status of the corresponding key. This method returns 1 for Caps Lock and Num Lock when you press it once and leave it. But for Scroll Lock, it returns 1 only when the key is Held down.

So XQueryKeymap (in libX.so) method is responsible for the wrong results.

  xxxxx@xxxxx   2002-09-20
----------------------------------------------- 

Attached the C test case mentioned above.  

The only solution I can think of offhand is to keep a state variable that 
tracks whether ScollLock has been pressed an even or odd number of times.  
This isn't perfect, since it won't take into account the state of the 
ScrollLock on startup, and it won't track ScrollLock presses that take place 
when other applications have the keyboard focus, but it may be the best we 
can do.  

  xxxxx@xxxxx   2002-09-22

It would be interesting to know how the kana lock key works: like the 
ScrollLock, or like the CapsLock? 

  xxxxx@xxxxx   2002-09-22

4757896 has been filed about the result of XQueryKeymap on Solaris.  
Note that this problem also exists in some or all Linux distributions.  
  xxxxx@xxxxx   2002-10-04
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang