ftguy2018 Posted October 1, 2018 Share Posted October 1, 2018 Is there a way to prevent a key event to be forwarded to the browser ? In firefore backspace is reloading the page and the only way I could prevent this to happen is to set the attribute preventDefault to true however it will block all keys so I would like only to have the backspace key not to be forwarded because I am using it in my own inputfield, so is it a way to accomplish this ? Thank you Quote Link to comment Share on other sites More sharing options...
Mobler Posted October 1, 2018 Share Posted October 1, 2018 HI, show how do you use preventDefault. I don't now how work 'Panda 2', but in JS i write something like that window.addEventListener( "keydown", (evt)=> { var keyCode = evt.keyCode; if (keyCode != 0 && keyCode == 8) { // your code is here evt.preventDefault(); } } ); I hope this helps you ftguy2018 1 Quote Link to comment Share on other sites More sharing options...
icp Posted October 1, 2018 Share Posted October 1, 2018 You can try this library to prevent default behavior for specific keys : https://craig.is/killing/mice . Mousetrap.bind("backspace", function (e){ e.preventDefault(); }); ftguy2018 1 Quote Link to comment Share on other sites More sharing options...
enpu Posted October 1, 2018 Share Posted October 1, 2018 You can also return true in your scene's keydown function to prevent default action on specific key: game.createScene('Main', { keydown: function(key) { if (key === 'BACKSPACE') return true; } }); ftguy2018 1 Quote Link to comment Share on other sites More sharing options...
ftguy2018 Posted October 2, 2018 Author Share Posted October 2, 2018 thank you everybody for your suggestion , I am currently using the keyboard.key function and I just realized that there is also scene methods for detecting keydown event ....I will adjust the code accordingly. Quote Link to comment Share on other sites More sharing options...
ftguy2018 Posted October 2, 2018 Author Share Posted October 2, 2018 15 hours ago, Mobler said: HI, show how do you use preventDefault. I don't now how work 'Panda 2', but in JS i write something like that window.addEventListener( "keydown", (evt)=> { var keyCode = evt.keyCode; if (keyCode != 0 && keyCode == 8) { // your code is here evt.preventDefault(); } } ); I hope this helps you I was using the config file with a keyboard section keyboard: { preventDefault: true }, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.