Num pad Enter key returns UNDEFINED [message #1794793] |
Thu, 06 September 2018 14:52 |
Patrick Muscat Messages: 14 Registered: May 2018 |
Junior Member |
|
|
Hello,
I'm not sure this is the right place for this problem...
Using JavaFX inside SWT, the keycode of the enter key from the numpad is UNDEFINED.
Here is a very simple example:
package enterkey;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import javafx.embed.swt.FXCanvas;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
public class TestJavaFXInsideSWT {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final FXCanvas fxCanvas = new FXCanvas(shell, SWT.FILL);
TextField textField = new TextField("Texte");
textField.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<Event>() {
@Override
public void handle(Event event) {
if (event instanceof KeyEvent)
System.out.println(((KeyEvent) event).getCode());
}
});
Group group = new Group(textField);
Scene scene = new Scene(group, 160, 80);
fxCanvas.setScene(scene);
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
With pure Javafx everything is fine
package enterkey;
import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import javafx.stage.Stage;
public class TestJavaFX extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Test EnterKey");
TextField textField = new TextField("Texte");
textField.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<Event>() {
@Override
public void handle(Event event) {
if (event instanceof KeyEvent)
System.out.println(((KeyEvent) event).getCode());
}
});
Group group = new Group(textField);
Scene scene = new Scene(group, 160, 80);
primaryStage.setScene(scene);
primaryStage.show();
}
}
With pure SWT, the keycode is different
package enterkey;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class TestSWT {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Text text = new Text(shell, SWT.NONE);
text.setText("Texte");
text.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
// ignorer
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println(e.keyCode);
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
Any idea or somewhere else to ask?
[Edit] versions:
- jfxswt from jre1.8.0_181
- org.eclipe.swt 3.106.2 (v20171129-0543)
- org.eclipse.swt.win32.win32.x86_64 3.106.2 (.v20171129-0543)
[Updated on: Thu, 06 September 2018 14:59] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04716 seconds