Doubts on KeyCode
Benjamin Gudehus
hastebrot at gmail.com
Mon Mar 30 11:56:04 UTC 2015
Hi,
>What I can not explain is why the keyboard "+" (ascii-code 43) maps to
"]" (ascii-code 93) from a native-keyevent to KeyCode happens in
Glass-Layer.
Hmm, the "+" key on a german keyboard layout [1] is actually "]" on the us
keyboard layout [2].
But when I type "+" on my german keyboard with german layout activated on
Windows it outputs "+" as unicode string and "PLUS" for the KeyCode. With
this code:
textField.setOnKeyPressed((event) -> {
System.out.println(event.getText());
System.out.println(event.getCode());
});
[1]
http://upload.wikimedia.org/wikipedia/commons/thumb/3/36/KB_Germany.svg/800px-KB_Germany.svg.png
[2]
http://upload.wikimedia.org/wikipedia/commons/thumb/5/51/KB_United_States-NoAltGr.svg/800px-KB_United_States-NoAltGr.svg.png
On Mon, Mar 30, 2015 at 1:19 PM, Scott Palmer <swpalmer at gmail.com> wrote:
> If I recall correctly there is one keycode named PLUS and another named
> ADD. One of them refers to the numeric keypad.
>
> Scott
>
> > On Mar 30, 2015, at 6:58 AM, Tom Schindl <tom.schindl at bestsolution.at>
> wrote:
> >
> > hi,
> >
> > suppose you have the following code:
> >
> >> package application;
> >>
> >> import javafx.application.Application;
> >> import javafx.scene.Scene;
> >> import javafx.scene.control.TextField;
> >> import javafx.scene.layout.BorderPane;
> >> import javafx.stage.Stage;
> >>
> >> public class Main extends Application {
> >> @Override
> >> public void start(Stage primaryStage) {
> >> try {
> >> BorderPane root = new BorderPane();
> >> Scene scene = new Scene(root, 400, 400);
> >>
> >> TextField f = new TextField();
> >> f.setOnKeyReleased( e -> {
> >> System.err.println(e.getCode());
> >> });
> >> root.setCenter(f);
> >>
> >> primaryStage.setScene(scene);
> >> primaryStage.show();
> >> } catch (Exception e) {
> >> e.printStackTrace();
> >> }
> >> }
> >>
> >> public static void main(String[] args) {
> >> launch(args);
> >> }
> >> }
> >
> > For default ASCII-Chars like a, b, c, ... I get the correct KeyCode but
> > e.g. for +, -, ... the information is totally bogus. Please note I get
> > the correct keyCode when pressing the NumPad char but e.g. CLOSE_BRACKET
> > when pressing "+" on my keyboard.
> >
> > If I'm not completely mistaken the KeyCode defintion for the current +
> > is the one for the keypad "+" and the one for the ordinary + is missing?
> >
> > This means that the definition:
> >
> > PLUS(0x0209, "Plus")
> >
> > has to be
> >
> > PLUS(0x0209, "Plus", KeyCodeClass.KEYPAD)
> >
> > What I can not explain is why the keyboard "+" (ascii-code 43) maps to
> > "]" (ascii-code 93) from a native-keyevent to KeyCode happens in
> > Glass-Layer.
> >
> > Tom
> >
> > --
> > Thomas Schindl, CTO
> > BestSolution.at EDV Systemhaus GmbH
> > Eduard-Bodem-Gasse 5-7, A-6020 Innsbruck
> > http://www.bestsolution.at/
> > Reg. Nr. FN 222302s am Firmenbuchgericht Innsbruck
>
More information about the openjfx-dev
mailing list