How to change scene upon pressing enterkey?


(nur) #1

I have a input box, where user need to type their text and press enter to go to the next scene.

I think this requires javascript but I’m really a noob here so I might need some help here.


#2

Hi @nasgerl

Here is something to help you.

Note that the keycode for enter is “13”.

What you do is go to the Scene Inspector and create a “run javascript…” on “scene load” and create a “new function” and in this function place the following code …

window.text = document.getElementById("input1"); // the input element inside the text element
	
text.addEventListener("keypress", function(event) { // the listener. Listens for events on the input element

if (event.keyCode == 13) // enter is pressed
	        hypeDocument.showNextScene(hypeDocument.kSceneTransitionCrossfade, 1.1); // go to next scene
	});

This assumes you have an ID of “input1” for your input box.

textInputListener.zip (22.2 KB)


(nur) #3

Hi!

Thanks. THe script is working on my side. :smiley:


#4

Great! could you mark the answer as solved (tick inside a box) next to the heart.