Triggering/Simulating Key presses from C++ [cef client]

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

Triggering/Simulating Key presses from C++ [cef client]

Postby sijusamuel » Wed Jan 29, 2014 2:27 pm

From cefclient(c++-windows) do there have any easy option to trigger KeyPresses.

In my specific case, I get input key code from a braille display device using C++/cefclient and these codes can be
mapped to english characters or unicodes . After the mapping it should behave as a normal Keyboard
entry in cef browser. Do there have any easy option/hook point in CEF to simulate key presses ? So that it will give the exact
behaviour as that of keyboard presses. Any input is highly appreciated.
sijusamuel
Techie
 
Posts: 10
Joined: Fri Oct 25, 2013 4:21 pm

Re: Triggering/Simulating Key presses from C++ [cef client]

Postby magreenblatt » Wed Jan 29, 2014 4:42 pm

Use CefBrowserHost::SendKeyEvent.
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm

Re: Triggering/Simulating Key presses from C++ [cef client]

Postby sijusamuel » Thu Jan 30, 2014 4:47 pm

Thanks. I simulated sending KeyPress in Cefclient 3 using SendKeyEvent as below ( by referring code from one of the osr_test from CEF3). It works for a-z characters ( for example sending 'a' is fine. But any characters like '.' or '=' etc throws error . Error is [ File;:\dd\vctools\crt_bld\self_x86\crt\src\isctype.c, Line 56, Expression: (Unsigned)(c+1) < 256]. Is it required to do any thing differently.

//const char kKeyTestWord[] = "th"; //Works fine
//const char kKeyTestWord[] = "th ."; //Error when sending '.' for KEYEVENT_RAWKEYDOWN
const char kKeyTestWord[] = "."; //Error when sending '.' for KEYEVENT_RAWKEYDOWN

size_t word_length = strlen(kKeyTestWord);
for (size_t i = 0; i < word_length; ++i) {
BYTE VkCode = LOBYTE(VkKeyScanA(kKeyTestWord[i]));
UINT scanCode = MapVirtualKey(VkCode, MAPVK_VK_TO_VSC);
eventToTest.native_key_code = (scanCode << 16) | // key scan code
1; // key repeat count
eventToTest.windows_key_code = VkCode;
eventToTest.type = KEYEVENT_RAWKEYDOWN;
browser->GetHost()->SendKeyEvent(eventToTest);

//-----
eventToTest.windows_key_code = kKeyTestWord[i];
eventToTest.type = KEYEVENT_CHAR;
browser->GetHost()->SendKeyEvent(eventToTest);

//---------
eventToTest.windows_key_code = VkCode;
// bits 30 and 31 should be always 1 for WM_KEYUP
eventToTest.native_key_code |= 0xC0000000;
eventToTest.type = KEYEVENT_KEYUP;
browser->GetHost()->SendKeyEvent(eventToTest);
}
Can you please suggestr ? Also what is the significance of 1; // key repeat count ?
sijusamuel
Techie
 
Posts: 10
Joined: Fri Oct 25, 2013 4:21 pm


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 18 guests