JDK-4744373 : Toolkit.getLockingKeyState() does not return Scroll lock state
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: linux
  • CPU: x86
  • Submitted: 2002-09-10
  • Updated: 2005-12-29
Related Reports
Relates :  
Relates :  
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));
    }
  }
}

Comments
EVALUATION Commit to fix in tiger. ###@###.### 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. ###@###.### 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. ###@###.### 2002-09-22 It would be interesting to know how the kana lock key works: like the ScrollLock, or like the CapsLock? ###@###.### 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. ###@###.### 2002-10-04
22-09-2002