Disable F5 and other commands in WebView2?

0 favourites
  • 13 posts
From the Asset Store
In this game you will command the character by voice command.
  • Is there a way to prevent WebView2 to prompt page refresh with F5, and other commands as well with F7 etc?

  • Oooh interesting, I utilise F keys in my project, but haven't tested it yet. Does it get overridden if you have an "on f5 pressed" event present? I'm guessing not, but wanted to check.

  • Oooh interesting, I utilise F keys in my project, but haven't tested it yet. Does it get overridden if you have an "on f5 pressed" event present? I'm guessing not, but wanted to check.

    It doesn't unfortunatly

  • Put this into the runOnStartup function in main.js

    document.addEventListener('keydown', function(event) {
     		if (event.key === 'F5') {
     		event.preventDefault();
     		}
    	});
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Put this into the runOnStartup function in main.js

    > document.addEventListener('keydown', function(event) {
    		if (event.key === 'F5') {
    		event.preventDefault();
    		}
    	});

    Doesn't this unfortunately prevent the game from running in Worker Mode? Which means that you'll lose performance/smoothness by doing it.

  • Put this into the runOnStartup function in main.js

    > document.addEventListener('keydown', function(event) {
    		if (event.key === 'F5') {
    		event.preventDefault();
    		}
    	});

    I tried to open the main.js file with notepad++ and it's a wall of text, how can i show the code as in your screenshot?

  • In addition, there are more browser commands that are messing with my exported game: aside the F keys, when i hold alt and than move with WASD, my character gets stuck and there's a window alert sound.

  • I think these issues need to be reported as bugs:

    github.com/Scirra/Construct-bugs/issues

    WebView2 is a desktop export, it is not supposed to have such limitations.

  • > Put this into the runOnStartup function in main.js

    >

    >

    > > document.addEventListener('keydown', function(event) {
    > 		if (event.key === 'F5') {
    > 		event.preventDefault();
    > 		}
    > 	});

    >

    >

    >

    >

    I tried to open the main.js file with notepad++ and it's a wall of text, how can i show the code as in your screenshot?

    You don't need to get into the engine files.

    You need to add a file to the project and insert the necessary code there.

  • Doesn't this unfortunately prevent the game from running in Worker Mode? Which means that you'll lose performance/smoothness by doing it.

    Hmm yeah I think that's the case. You can also edit the exported index.html though like so, which should keep the worker mode enabled I think.

    But I there should be an in-engine way to handle this. A "prevent default" plugin or something, because it's one of those topics that comes up over and over again.

    BTW, this code should disable all keyboard inputs, iirc including alt+F4, F12 and such.

    document.addEventListener('keydown', function(event) {
     	event.preventDefault();
    	});
  • > Doesn't this unfortunately prevent the game from running in Worker Mode? Which means that you'll lose performance/smoothness by doing it.

    Hmm yeah I think that's the case. You can also edit the exported index.html though like so, which should keep the worker mode enabled I think.

    But I there should be an in-engine way to handle this. A "prevent default" plugin or something, because it's one of those topics that comes up over and over again.

    BTW, this code should disable all keyboard inputs, iirc including alt+F4, F12 and such.

    > document.addEventListener('keydown', function(event) {
    	event.preventDefault();
    	});

    You sir saved my life!

    Will adding this to main.js script prevent worker mode?

  • Yep it does prevent worker mode. Now a way to have it and keep worker mode would be the best of both worlds!

  • This is clearly an oversight on Ashley's part. Please report or post a suggestion. A desktop export with browser keyboard limitations is pretty meaningless.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)