Keypresses not working locally on PC

Anyone have any idea why the below keypress code works locally and online on Mac/Safari/Chrome, but only works online on a PC, and not locally even in the exact same browser…?

if (event.keyCode == 82) { // ’R’ Key
    hypeDocument.showSceneNamed("intro",
    hypeDocument.kSceneTransitionCrossfade, 0.3);
}

if (event.keyCode == 83) { // ’S’ Key
    hypeDocument.showSceneNamed("slidedeck",
    hypeDocument.kSceneTransitionCrossfade, 0.3);
}





if (event.keyCode == 37) { // ’LEFT’ Key
    hypeDocument.showPreviousScene(
    hypeDocument.kSceneTransitionCrossfade, 0.3);
}

if (event.keyCode == 38) { // ’UP’ Key
    hypeDocument.showPreviousScene(
    hypeDocument.kSceneTransitionCrossfade, 0.3);
}

if (event.keyCode == 39) { // ’RIGHT’ Key
    hypeDocument.showNextScene(
    hypeDocument.kSceneTransitionCrossfade, 0.3);
}

if (event.keyCode == 40) { // ’DOWN’ Key
    hypeDocument.showNextScene(
    hypeDocument.kSceneTransitionCrossfade, 0.3);
}

if (event.keyCode == 32) { // ’SPACE’ Key
    hypeDocument.showNextScene(
    hypeDocument.kSceneTransitionCrossfade, 0.3);
}

I’m surprised no one responded to you. Perhaps the KEEN FAQ has the answer…

Q. So what’s this other data?
A. The original “KeyCodes” are deprecated. (That means it’s being phased out.) The modernized way is to use the new “Key” property. This information is also displayed in “KEEN”. If you want to know the exact string returned from a JavaScript “e.key”, “e.code” or “e.keyCode” event, it’s shown at the bottom-left corner of KEEN.

…but apparently “keycode” should still work…

https://caniuse.com/#feat=mdn-api_keyboardevent_keycode

My “Velocity” template is somewhat similar to what you’re doing with key codes…

…so I’m not quite sure why it’s not working. Perhaps that’s why no one replied. :blush:

The code looks fine to me… my guess would be there could be another problem happening elsewhere as the result of using a file:/// URL that is causing an exception and perhaps stopping this code from running. These are usually CORS related issues where resources cannot be fetched via HTTPS.

To diagnose beyond this, it would be useful to have:

  • A zip of your .hype document exhibiting the problem
  • The export that you are using
  • The version of windows you are using
  • The browser/version you are using
  • Any other instructions on running the file
1 Like