Number Keys Jump to Scene


(Jud) #1

How would the JavaScript code flow if I made each key 1-8 on the keypress jump to a different scene? I have eight session scenes. Key 1 jumps to Scene 1, etc…


(Mark Hunte) #2

Hi,

I must admit I am a bit perplexed that you ask this after you should already have the code to work it out from the example in the link given in your play/pause question ??


#4

Hey @Judboy, I’ve hidden this topic as this does seem like you already have the answer. You would just need the key code for those numbers paired with the Hype API which you have experience with.


(Jud) #5

Got it! Thx.


(Jud) #6

This appears to work fine for me. I just have to hold the key down instead of a quick tap. BTW - What is the difference between on key press and key down?

document.onkeydown = checkKey;

function checkKey(e) {
    e = e || window.event;
    if (e.keyCode == '49') {
        //number two button
        hypeDocument.showSceneNamed('Session One', hypeDocument.kSceneTransitionCrossfade, 1.1)
    }
    if (e.keyCode == '50') {
        //number two button
        hypeDocument.showSceneNamed('Session Two', hypeDocument.kSceneTransitionCrossfade, 1.1)
    }
    if (e.keyCode == '51') {
        //number two button
        hypeDocument.showSceneNamed('Session Three', hypeDocument.kSceneTransitionCrossfade, 1.1)
    }
    if (e.keyCode == '52') {
        //number two button
        hypeDocument.showSceneNamed('Session Four', hypeDocument.kSceneTransitionCrossfade, 1.1)
    }
    if (e.keyCode == '53') {
        //number two button
        hypeDocument.showSceneNamed('Session Five', hypeDocument.kSceneTransitionCrossfade, 1.1)
    }
    if (e.keyCode == '54') {
        //number two button
        hypeDocument.showSceneNamed('Session Six', hypeDocument.kSceneTransitionCrossfade, 1.1)
    }
    if (e.keyCode == '55') {
        //number two button
        hypeDocument.showSceneNamed('Session Seven', hypeDocument.kSceneTransitionCrossfade, 1.1)
    }
    if (e.keyCode == '56') {
        //number two button
        hypeDocument.showSceneNamed('Session Eight', hypeDocument.kSceneTransitionCrossfade, 1.1)
    }
}

#7

I googled ‘difference between keydown and keypress’ and found this:

The :key: thing is:

The KeyPress event is not raised by noncharacter keys; however, the noncharacter keys do raise the KeyDown and KeyUp events.

Key events occur in the following order:

KeyDown
KeyPress
KeyUp

So using keydown is better to handle all types of Keys (spacebar, characters + numbers)


(Jud) #9

I will test tonight, but I wonder if Keydown will include the number keys with special characters. I know for sure keypress only includes the number keys at the top of keyboard with special characters. Also, wonder if you can have both keypress and keydown scripts run on the same scene


#10

Let us know what you find


(Jud) #11

In my project I found I needed the keypress for the number keys that also have special characters. The lkeydown did not not nclude those keys in my project. Keydown would only include my number keys without special characters.