On Sat, 23 Jan 2021 23:12:35 GMT, Nir Lisker <[email protected]> wrote:
>> The JavaFX API does not provide a way to get the state of CAPS LOCK or NUM
>> LOCK on the keyboard. Being able to read the lock state would allow an
>> application to inform the user that caps lock was enabled for passwords or
>> other usages where the keyboard input might not be echoed. It would also
>> allow an application to do spell checking / auto-correction that might
>> ordinarily be skipped when typing all upper-case letters.
>>
>> We need an equivalent JavaFX API to the existing AWT
>> `java.awt.ToolKit::getLockingKeyState` method. A natural place to put this
>> in JavaFX is in the `javafx.application.Platform` class, so we propose to
>> create a new `Platform::isKeyLocked` method, which will take a `KeyCode` --
>> either `CAPS` or `NUM_LOCK` -- and return an `Optional<Boolean>` indicating
>> whether or not that key is in the locked or "on" state. If we can't read the
>> key state on a particular platform, we will return `Optional.empty()`,
>> rather than throwing a runtime exception as AWT does.
>>
>> I have provided both an automated Robot test and a manual test. The latter
>> is needed primarily because we can't set the CAPS lock on Mac using Robot,
>> but also because we want way to test the case where the user has enabled
>> CAPS lock before the program starts.
>
> modules/javafx.graphics/src/main/java/com/sun/javafx/tk/quantum/QuantumToolkit.java
> line 1250:
>
>> 1248: default:
>> 1249: return com.sun.glass.events.KeyEvent.VK_UNDEFINED;
>> 1250: }
>
> Also expression switch here.
See above.
> modules/javafx.graphics/src/main/java/javafx/application/Platform.java line
> 336:
>
>> 334: /**
>> 335: * Returns a flag indicating whether the key corresponding to
>> {@code keyCode}
>> 336: * is in the locked or "on" state.
>
> I would write "locked, or "on", state" or "locked (or "on") state" because in
> the current form it can be understood as 2 different conditions.
Agreed. This was nagging at the back of my mind when I read it, but I didn't do
anything about it.
-------------
PR: https://git.openjdk.java.net/jfx/pull/385