public final class CapsLockSupport extends AbstractBean implements KeyEventDispatcher
CAPS LOCK
key
. It also supports notification when the locking state changes.
Although it is possible to use Toolkit.getLockingKeyState(int)
to determine the current
state of the CAPS LOCK key, that method is not guaranteed to work on all platforms. This class
attempts to handle those shortfalls and provide an easy mechanism for listening to state changes.
CapsLockSupport cls = CapsLockSupport.getInstance(); // for get the current state of the caps lock key boolean currentState = cls.isCapsLockEnabled(); // for listening to changes in the caps lock state cls.addPropertyChangeListener("capsLockEnabled", myListener);There is one special case to be aware of. If
CapsLockSupport
is not able to determine the
state of the CAPS LOCK key, then isInitialized()
will return false
until it is
able to introspect a KeyEvent
and determine the current locking state. If
CapsLockSupport
must use delayed initialization, it will fire a property change to notify
listeners that it is now in an accurate state.Modifier and Type | Method and Description |
---|---|
boolean |
dispatchKeyEvent(KeyEvent e)
This is an implementation detail and should not be considered public.
|
static CapsLockSupport |
getInstance()
Gets the only instance of
CapsLockSupport . |
boolean |
isCapsLockEnabled()
Determines the current state of the
CAPS LOCK key . |
boolean |
isInitialized()
Determines if
CapsLockSupport is accurately synchronized with the state of the CAPS
LOCK key. |
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, clone, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
public static CapsLockSupport getInstance()
CapsLockSupport
.CapsLockSupport
instancepublic boolean isInitialized()
CapsLockSupport
is accurately synchronized with the state of the CAPS
LOCK key. When not initialized, isCapsLockEnabled()
will always return false
. CapsLockSupport
will fail to initialize only if
Toolkit#getLockingKeyState(int)
throws an exception; in that case, it will initialize
as soon as it receives a valid key event (that can be used to determine the current locking
state).true
if CapsLockSupport
accurately knows the state of the CAPS LOCK
keypublic boolean isCapsLockEnabled()
CAPS LOCK key
.true
if CAPS LOCK is enabled; false
otherwisepublic boolean dispatchKeyEvent(KeyEvent e)
dispatchKeyEvent
in interface KeyEventDispatcher
Copyright © 2013. All Rights Reserved.