MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / sendKeys

Function sendKeys

cpp/webdriver-interactions/interactions.cpp:393–650  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

391extern "C"
392{
393void sendKeys(WINDOW_HANDLE windowHandle, const wchar_t* value, int timePerKey)
394{
395 if (!windowHandle) {
396 LOG(WARN) << "Window handle is invalid";
397 return;
398 }
399
400 HWND directInputTo = static_cast<HWND>(windowHandle);
401
402 HKL layout = attachInputToIEThread(directInputTo);
403 BYTE keyboardState[256];
404 ::ZeroMemory(keyboardState, sizeof(keyboardState));
405
406 bool controlKey = controlPressed;
407 bool shiftKey = shiftPressed;
408 bool altKey = altPressed;
409 KeySendingData sendData;
410 sendData.to_window = directInputTo;
411 sendData.layout = layout;
412 sendData.keyboardState = keyboardState;
413 sendData.pause_time = timePerKey;
414
415 for (const wchar_t *p = value; *p; ++p) {
416 const wchar_t c = *p;
417
418 bool extended = false;
419
420 UINT scanCode = 0;
421 WORD keyCode = 0;
422
423 if (isModifierCharacter(c)) {
424 sendModifierKeyEvent(c, shiftKey, controlKey, altKey, sendData);
425 shiftPressed = shiftKey;
426 controlPressed = controlKey;
427 altPressed = altKey;
428 continue;
429 } else if (c == 0xE001U) { // ^break
430 keyCode = VK_CANCEL;
431 scanCode = keyCode;
432 extended = true;
433 } else if (c == 0xE002U) { // help
434 keyCode = VK_HELP;
435 scanCode = keyCode;
436 } else if (c == 0xE003U) { // back space
437 keyCode = VK_BACK;
438 scanCode = keyCode;
439 } else if (c == 0xE004U) { // tab
440 keyCode = VK_TAB;
441 scanCode = keyCode;
442 } else if (c == 0xE005U) { // clear
443 keyCode = VK_CLEAR;
444 scanCode = keyCode;
445 } else if (c == 0xE006U) { // return
446 keyCode = VK_RETURN;
447 scanCode = keyCode;
448 } else if (c == 0xE007U) { // enter
449 keyCode = VK_RETURN;
450 scanCode = keyCode;

Callers

nothing calls this directly

Calls 7

attachInputToIEThreadFunction · 0.85
isModifierCharacterFunction · 0.85
sendModifierKeyEventFunction · 0.85
backgroundKeyPressFunction · 0.85
detachInputFromIEThreadFunction · 0.85
LOGClass · 0.70

Tested by

no test coverage detected