Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

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

Post Reply
Miklos B.
Posts: 1
Joined: Wed Jan 06, 2021 10:35 am

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

Post 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>
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

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

Post by salvadordf »

Try calling TChromium.SetFocus(True) and/or TChromium.SendFocusEvent(True) when the application gets the focus.
Post Reply