Intercept ALT and Fn keys - not supported :OnPreKeyEvent?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Intercept ALT and Fn keys - not supported :OnPreKeyEvent?

Postby HarmlessDave » Fri Aug 21, 2015 4:54 pm

Windows, 3.2272.1998

We want to add some ALT and F1 keyboard shortcuts but it seems like the chromium window is consuming them without passing them to the ::OnPreKeyEvent() event.

This works for control keys but not ALT - x, F1, F5:
Code: Select all
bool ClientHandler::OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
                                  const CefKeyEvent& event, CefEventHandle os_event, bool* is_keyboard_shortcut) {
  CEF_REQUIRE_UI_THREAD();

  if (hAccelTable != NULL && os_event != NULL)
  {
        BOOL message_handled = TranslateAccelerator(mainframe_hwnd, hAccelTable, os_event);
   if (message_handled)
   {
     LogTRACE0("CEF3 aceel table");
          return true;
   }
  }


Are ALT and Fn keys supposed to be trappable and I'm doing something wrong? Or are the old threads from 2009-12 still correct and I either need to edit the chromium source or subclass the first child of the browser window like in this thread? - viewtopic.php?f=6&t=898&p=3577&hilit=pretranslatemessage#p3577

Edit: Placing a TranslateAccelerator() in the parent window (that has the browser object as a child) also works for trapping the CTRL hotkeys (but not ALT, Fn), though the one in OnPreKeyEvent() takes priority over it if both are enabled.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: Intercept ALT and Fn keys - not supported :OnPreKeyEvent

Postby magreenblatt » Fri Aug 21, 2015 5:01 pm

Are you sure ClientHandler::OnPreKeyEvent isn't being called for those keyboard combinations? |os_event| might be NULL.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Intercept ALT and Fn keys - not supported :OnPreKeyEvent

Postby HarmlessDave » Fri Aug 21, 2015 5:36 pm

Edit: this DOES work in cefclient, so it looks like I'll need to figure out why it fails in our app:

Code: Select all
  if (event.type == KEYEVENT_RAWKEYDOWN)
  {
     if (event.windows_key_code == VK_F1)
     {
        MessageBoxA(NULL, "RawKeydown F1", "Hello", MB_OK);
     }
  }


Edit2: sigh, this was a bug in our code. Next time I'll check the plain cefclient BEFORE posting :)

But it was helpful to know that we could not count on os_event being non-NULL for the "system" keys like ALT-??, thanks!
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 89 guests