How do I prevent esc from exiting full-screen in macOS/WKWebView?

Not favoritedFavorited Favorited 0 favourites
  • 3 posts
From the Asset Store
Antisuspend Plugin for Construct 3 prevents the runtime from getting suspended.
  • I am trying to publish a multi-platform game (Windows/Webview2; Linux/CEF; macOS/WKWebView).

    My pause control is mapped to the escape key. On Windows & Linux, this is fine. However, in the macOS version, the esc press will exit fullscreen.

    Is there some way to intercept the keypress events so that the escape key is only used in-game and doesn't un-fullscreen the browser?

    Or do I just need to change my keybinds on mac to avoid this issue?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Update: I found a way to do this - I just attach an event listener to the document in my init script, which catches tab/escape keypresses.

    // Intercept Tab/Esc keys (this only works if web worker mode is disabled)
    if(globalThis.hasOwnProperty("document")) {
    	document.addEventListener("keydown", e => {
    		if(e.key == "Tab" || e.key == "Escape")
    			e.preventDefault();
    	});
    }
    else {
    	console.warn("Running on a web worker; can't intercept tab/esc events!");
    }

    The only limitation is that this doesn't work in web worker mode because web workers don't have access to the document object.

    I don't suppose there's a way to inject this snippet into the main thread so that it runs once before the game engine even starts?

  • Update 2: I found a very recent addon that serves this exact purpose. Thanks for uploading it, MasterPose!

    construct.net/en/make-games/addons/1531/dom-side

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