C
C
crescent2021-10-31 18:43:34
C++ / C#
crescent, 2021-10-31 18:43:34

CefSharp key event?

There is a windows form in which cef is inserted
. So this cef intercepts all keyboard presses and I cannot catch them from the form.
How can I fix this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim K, 2021-10-31
@mkvmaks

In my initialization, I did this: this.KeyPreview = true;
Then I made invisible buttons and hung regular keystrokes on them.
Through a class like this:

public class KeyboardHandler : IKeyboardHandler
    {
        public bool OnPreKeyEvent(IWebBrowser chromiumWebBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut)
        {
            if (type == KeyType.KeyUp && Enum.IsDefined(typeof(Keys), windowsKeyCode))
            {
                var key = (Keys)windowsKeyCode;
                switch (key)
                {
                    case Keys.F5:
                        browser.Reload(true);
                        break;
                }
            }
            return false;
        }

        public bool OnKeyEvent(IWebBrowser chromiumWebBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey)
        {
            var result = false;
            return result;
        }
    }
}

I couldn't get my buttons to fit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question