raylib icon indicating copy to clipboard operation
raylib copied to clipboard

[rcore][web] Pressing F1 opens a help tab in certain chromium based browsers

Open Moros1138 opened this issue 8 months ago • 0 comments

Issue description

In Microsoft Edge and Google Chrome I have noticed pressing F1 opens a help tab.

Repoduce in the affected browsers by following these steps:

  1. Visit: https://www.raylib.com/examples/shapes/loader.html?name=shapes_top_down_lights
  2. click anywhere in the running example to ensure it has focus
  3. Press 'F1' key
  4. See the problem.

I assume, given the pattern involves Chromium based browsers that this is true of other similarly based browsers. Firefox was unaffected.

Environment

Windows 11 Microsoft Edge Version 136.0.3240.76 (Official build) (64-bit) Google Chrome Version 136.0.7103.114 (Official Build) (64-bit)

Possible Solution

I fixed this locally in my own build adding the following to my shell:

        document.addEventListener('keydown', function(event)
        {
            if (event.key == 'F1' || event.keyCode == 112)
                event.preventDefault();
        });

this could easily be integrated into the web platform code like so:

EM_ASM({
        document.addEventListener('keydown', function(event)
        {
            if (event.key == 'F1' || event.keyCode == 112)
                event.preventDefault();
        });
});

Probably somewhere in InitPlatform.

Moros1138 avatar May 21 '25 21:05 Moros1138