In this code (attached) , you can see mouseEvents are understandable by the second scene but key events are not.
Workaround : Press ALT+TAB key (twice) to get the focus back into the application window, this time key event works well
-------------------------------------------------------------------- Code Begins --------------------------------------------------------------------
/*
* Main.fx
*
* Created on Dec 1, 2008, 11:18:07 AM
*/
package keyeventscene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.stage.Stage;
var zoom = 1.0;
var s_new : Scene;
var s = Scene {
fill: Color.BLACK
content: [
ImageView {
translateX: 80
translateY: 100
image: Image {
height: 60
width: 60
url: "{__DIR__}flower1.PNG"
}
onMouseClicked: function( e: MouseEvent ):Void {
s_new = s1;
}
onKeyPressed: function( e: KeyEvent ):Void {
if(e.code == KeyCode.VK_ENTER){
s_new = s1;
}
}
},
Text {
x: 20
y: 200
fill: Color.WHITE
content: "Press Enter or click on the \nphoto to go to the next scene"
}
]
};
var s1 = Scene {
fill: Color.BLACK
content: [
ImageView {
translateX: 80
translateY: 80
image: Image {
height: 60
width: 60
url: "{__DIR__}insect.PNG"
}
// opacity: bind op
scaleX: bind zoom
onMouseClicked: function( e: MouseEvent ):Void {
zoom = 0.5;
}
onKeyPressed:function(e:KeyEvent):Void {
if(e.code == KeyCode.VK_LEFT) {
zoom = 1.0 ;
}
if(e.code == KeyCode.VK_RIGHT) {
zoom = 2.0 ;
}
}
},
Text {
x: 20
y: 180
fill: Color.WHITE
content: "- Pressing Right/Left arrow keys should \nstress/shrink the image in X direction\n \n- Click on the image with mouse, \nimage get shrinked"
}
]
};
s_new = s;
Stage {
title: "Changing Scene"
width: 250
height: 280
scene: bind s_new
}
-------------------------------------------------------------------- Code Ends --------------------------------------------------------------------