Empty key input with ALT

Having problems with building or using the CefSharp .NET binding? Ask your CEF-related questions here. Please ask general usage questions on StackOverflow.

Moderator: amaitland

Empty key input with ALT

Postby spinalcord » Fri Aug 20, 2021 9:18 am

Hello,

I don't know whether this is an expected behaviour or not. But if I press CTRL + ALT + [SPECIFIC KEY] on any html input control (textfields, contenteditable, etc.), i will expect a symbol such as @ (German keyboard layout), but the alt key stops any further interactions.
This problem occures also in the Cef minimal example and also in a vanilla project. Is there something that I don't see?

I use( Windows 10/.Net 4.7.2/ x64/ Cef 92.0.26)

thanks in advance for any help.
spinalcord
Newbie
 
Posts: 5
Joined: Fri Aug 20, 2021 8:58 am

Re: Empty key input with ALT

Postby amaitland » Fri Aug 20, 2021 4:08 pm

What example did you test with exactly? CEF has it's own sample application.

Are you using WinForms or WPF?

If you haven't already please test with the CEF Sample application (cefclient), instructions at https://github.com/cefsharp/CefSharp/bl ... ameworkcef

Please confirm the command line args you tested with.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: Empty key input with ALT

Postby spinalcord » Fri Aug 20, 2021 4:37 pm

Hello amaitland,

I use WPF. I tested the CEF Sample application with following results.

WPF - Problem occurs with:
Code: Select all
 cefclient.exe --multi-threaded-message-loop --off-screen-rendering-enabled --enable-gpu --no-sandbox --disable-site-isolation-trials --disable-gpu-compositing


Windows Form - Working as expected with:
Code: Select all
 cefclient.exe --multi-threaded-message-loop --no-sandbox --disable-site-isolation-trials
spinalcord
Newbie
 
Posts: 5
Joined: Fri Aug 20, 2021 8:58 am

Re: Empty key input with ALT

Postby amaitland » Fri Aug 20, 2021 5:36 pm

You can add a breakpoint to https://github.com/cefsharp/CefSharp/bl ... r.cpp#L382

Recently improvements were made https://github.com/cefsharp/CefSharp/pull/3627

If you'd like to get involved and debug/fix the issue then a pull request is welcome. It's possible that changes to CEF might also need to be made.

Alternatively use https://www.nuget.org/packages/CefSharp.Wpf.HwndHost/
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: Empty key input with ALT

Postby spinalcord » Sat Aug 21, 2021 2:40 am

amaitland wrote:You can add a breakpoint to https://github.com/cefsharp/CefSharp/bl ... r.cpp#L382

Recently improvements were made https://github.com/cefsharp/CefSharp/pull/3627

If you'd like to get involved and debug/fix the issue then a pull request is welcome. It's possible that changes to CEF might also need to be made.

Alternatively use https://www.nuget.org/packages/CefSharp.Wpf.HwndHost/


Thank you for the advice : )
spinalcord
Newbie
 
Posts: 5
Joined: Fri Aug 20, 2021 8:58 am

Re: Empty key input with ALT

Postby spinalcord » Sat Aug 21, 2021 4:55 am

Hello again I was able to fix it. I just commented out the following "if" line below (CefBrowserHostWrapper.cpp). Everything works like expected (now).

Code: Select all
        keyEvent.type = KEYEVENT_CHAR;
        // mimic alt-gr check behaviour from
        // src/ui/events/win/events_win_utils.cc: GetModifiersFromKeyState
        // ----> if (IsKeyDown(VK_RMENU))
        // ----> {
            // reverse AltGr detection taken from PlatformKeyMap::UsesAltGraph
            // instead of checking all combination for ctrl-alt, just check current char
            HKL current_layout = ::GetKeyboardLayout(0);

            MessageBox(NULL, NULL, NULL, NULL);


            // https://docs.microsoft.com/en-gb/windows/win32/api/winuser/nf-winuser-vkkeyscanexw
            // ... high-order byte contains the shift state,
            // which can be a combination of the following flag bits.
            // 1 Either SHIFT key is pressed.
            // 2 Either CTRL key is pressed.
            // 4 Either ALT key is pressed.
            SHORT scan_res = ::VkKeyScanExW(wParam, current_layout);
            constexpr auto ctrlAlt = (2 | 4);
            if (((scan_res >> 8) & ctrlAlt) == ctrlAlt) // ctrl-alt pressed
            {
                keyEvent.modifiers &= ~(EVENTFLAG_CONTROL_DOWN | EVENTFLAG_ALT_DOWN);
                keyEvent.modifiers |= EVENTFLAG_ALTGR_DOWN;
            }
       // ----> }
spinalcord
Newbie
 
Posts: 5
Joined: Fri Aug 20, 2021 8:58 am

Re: Empty key input with ALT

Postby amaitland » Sat Aug 21, 2021 5:20 am

That's unlikely the correct solution. You'll need to find out what additional condition needs to be added to the if statement.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: Empty key input with ALT

Postby spinalcord » Sat Aug 21, 2021 5:35 am

This attempt works also. I think this should be the right solution?

Code: Select all
if (IsKeyDown(VK_RMENU)|| IsKeyDown(VK_LMENU)) // ----> OLD: if (IsKeyDown(VK_RMENU))
        {
            // reverse AltGr detection taken from PlatformKeyMap::UsesAltGraph
            // instead of checking all combination for ctrl-alt, just check current char
            HKL current_layout = ::GetKeyboardLayout(0);


            // https://docs.microsoft.com/en-gb/windows/win32/api/winuser/nf-winuser-vkkeyscanexw
            // ... high-order byte contains the shift state,
            // which can be a combination of the following flag bits.
            // 1 Either SHIFT key is pressed.
            // 2 Either CTRL key is pressed.
            // 4 Either ALT key is pressed.
            SHORT scan_res = ::VkKeyScanExW(wParam, current_layout);
            constexpr auto ctrlAlt = (2 | 4);
            if (((scan_res >> 8) & ctrlAlt) == ctrlAlt) // ctrl-alt pressed
            {
                keyEvent.modifiers &= ~(EVENTFLAG_CONTROL_DOWN | EVENTFLAG_ALT_DOWN);
                keyEvent.modifiers |= EVENTFLAG_ALTGR_DOWN;
            }
        }
spinalcord
Newbie
 
Posts: 5
Joined: Fri Aug 20, 2021 8:58 am

Re: Empty key input with ALT

Postby amaitland » Sat Aug 21, 2021 3:59 pm

Please create a pull request.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am


Return to CefSharp Forum

Who is online

Users browsing this forum: No registered users and 15 guests