Run JS if scene is

Here’s my JS code that I set to run on scene load:

document.onkeydown = checkKey;
function checkKey(e) {
	e = e || window.event;
	if (e.keyCode == '13') {
	hypeDocument.showSceneNamed('dashboard', hypeDocument.kSceneTransitionCrossfade, 0.2);
}

I’d like to run this code only if current scene is named 'hello'.
Any help appreciated.

Hei Matus, this should work:

document.onkeydown = checkKey;
myScene = hypeDocument.currentSceneName();

function checkKey(e) {
	e = e || window.event;
	
	if (e.keyCode == '13' && myScene == 'hello') {
		hypeDocument.showSceneNamed('dashboard', hypeDocument.kSceneTransitionCrossfade, 0.2);
	}
}
1 Like

Note that Scenes do have On Key Down handlers themselves in the Scene Inspector. So you could potentially setup a handler there. You would still need to look at the event.keyCode to filter the keystrokes yourself.