Page 1 of 1

Keydown/up event handling does not work after reactivation of CEF module

Posted: Wed Jan 06, 2021 12:20 pm
by Miklos B.
After reactivation of the CEF module or tab no keydown event will be handled at first, unless you click physically somewhere on the page. A virtual click via SendMouseClickEvent will not do the job. The issue is easy to reproduce on any of the demo applications like MiniBrowser or TabbedBrowser.

Delphi Version: 10.3
CEF Version: 87.1.12
Windows Version: Windows 10 Enterprise 64 Bit (vm on Macbook Pro 2019 i7-9750H 32Gb Ram)

Step by step guide to reproduce the error:
  1. Open a page using a CEF module
  2. Change to an other tab or Windows application
  3. Change back to the previous CEF module
  4. Try to press a button and handle the event without clicking the page first
A simple HTML sample to reproduce the issue:

Code: Select all

<html>
    <head>
        <script>
            window.onload = function(){
                document.addEventListener('keydown', function (e) {
                    if (e.ctrlKey) {
                       document.getElementById('testcontainer').style.backgroundColor = 'rgb(253, 166, 166)';
                    } 
                });
                document.addEventListener('keyup', function (e) {
                   document.getElementById('testcontainer').style.backgroundColor = 'red';
                });
            }
        </script>
        <style>
            div {
                width: 200px;
                height: 70px;
                padding: 10px;
                text-align: center;
                vertical-align: center;
                font-size: 50px;
                background-color: red;
                color: white;
                margin: 50px;
            }
            p {
                font-weight: bold;
                font-size: 20px;
            }
        </style>
    </head>
    <body>
        <div id='testcontainer'>
            CTRL
        </div>
        <p>
            Press the CTRL button to change the container color. If you change the tab or windows-process and change back, it will not work, unless you click the page. It works fine in Google Chrome and other Chromium based browsers.
        </p>
    </body>
</html>

Re: Keydown/up event handling does not work after reactivation of CEF module

Posted: Wed Jan 06, 2021 3:51 pm
by salvadordf
Try calling TChromium.SetFocus(True) and/or TChromium.SendFocusEvent(True) when the application gets the focus.