question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to prevent F keys and other browser shortcuts?

See original GitHub issue

Specification

  • pywebview version: 3.6.3
  • operating system: Windows 10
  • web renderer: Edge

Description

Hi everyone, I am building basic python desktop applications, I use various servers, flask, pywebio, etc. to build my GUI. I want my apps to provide the full desktop experience. On the pywebview window, when I click on F3 or use a shortcut like CTRL+F, edge reveals itself with a search bar. I don’t want it to reveal that it runs in a browser, so I used JavaScript code below but there is a problem, when my page loads slowly and if my server crashes, this JavaScript code won’t work and all the shortcuts and F keys will be active again. Is there another way to prevent browser shortcuts? This method that i use is really sketchy and doesn’t feel good.

let FKeys = [
  112, // F1
  113,
  114, // F3
  115,
  116, // F5 - Refresh
  117,
  118,
  119,
  120,
  121, // F10 - DevTools
  122, // F11 - Fullscreen
  123, // F12 - Dev Tools
];
let ForbiddenShortcutLetters = [
  "c", // Copy
  "v", // Paste
  "x", // Cut
  "s", // Save
  "p", // Print
  "w", // Close
  "u", // View Source
  "a", // Select All
  "z", // Undo
];
let ForbiddenShotcutKeyCodes = [
  73, // I
  69, // E
  74, // J
  70, // F
];
document.addEventListener("contextmenu", function (event) {
  event.preventDefault();
});
document.onkeydown = function (event) {
  console.log(event);
  if (FKeys.includes(event.keyCode)) {
    console.log("F key pressed");
    event.preventDefault();
    event.stopPropagation();
    return false;
  } else if (
    (event.ctrlKey || event.shiftKey || event.altKey) &&
    ForbiddenShortcutLetters.indexOf(event.key) !== -1
  ) {
    event.preventDefault();
    event.stopPropagation();
    return false;
  } else if (
    (event.ctrlKey || event.shiftKey || event.altKey) &&
    ForbiddenShotcutKeyCodes.includes(event.keyCode)
  ) {
    event.preventDefault();
    event.stopPropagation();
    return false;
  } else if (event.ctrlKey) {
    // Disable Ctrl
    event.preventDefault();
    event.stopPropagation();
    return false;
  } else if (event.shiftKey) {
    // Disable Shift
    event.preventDefault();
    event.stopPropagation();
    return false;
  } else if (event.altKey) {
    // Disable Alt
    event.preventDefault();
    event.stopPropagation();
    return false;
  }
};

Practicalities

  • YES I am willing to work on this issue myself.

  • NO I am prepared to support this issue financially.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
r0x0rcommented, Oct 3, 2022

Yes, this issue must be definitely addressed. Here is a discussion on the matter https://github.com/MicrosoftEdge/WebView2Feedback/issues/288

0reactions
vimevimcommented, Nov 30, 2022

@r0x0r You are the best, thanks a lot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

4 Ways to Disable the Function Key - wikiHow
1. Enter the system BIOS or UEFI. Depending on your computer manufacturer and BIOS version, you may be able to change the behavior...
Read more >
How do I stop f1 opening a browser window in WIN10. (shortcut
I want to remove the shortcut that makes the F1 key open the browser. I do NOT want to DISABLE the key. Just...
Read more >
How to Disable Hotkeys | How to Enable Function Keys
How to Disable Hotkeys | How to Enable Function KeysThe Function key allows the user of a business laptop to access additional functions...
Read more >
How to Disable Hotkeys / Enable Function Keys on Laptops
Have you ever been triggered by the action keys so called hotkeys on your laptop and the way they interfere, with the classic...
Read more >
How To Use Function Keys Without Pressing Fn Key On ...
This key is usually the Esc key or a completely separate key. All you have to do is look on your keyboard and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found