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

Function backgroundKeyDown

cpp/webdriver-interactions/interactions.cpp:169–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167}
168
169void backgroundKeyDown(HWND hwnd, HKL layout, BYTE keyboardState[256],
170 WORD keyCode, UINT scanCode, bool extended, int pause)
171{
172 // For capital letters and symbols requiring the shift key to be pressed,
173 // A Shift key press must preceed. Unless the shift key is pressed - if
174 // shiftPressed is true, then a shift key-down was sent in the past.
175 sendModifierKeyDownIfNeeded(isShiftPressNeeded(keyCode) && (!shiftPressed), hwnd, layout,
176 VK_SHIFT, keyboardState, pause);
177
178 sendModifierKeyDownIfNeeded(isControlPressNeeded(keyCode) && (!controlPressed), hwnd, layout,
179 VK_CONTROL, keyboardState, pause);
180
181 sendModifierKeyDownIfNeeded(isAltPressNeeded(keyCode) && (!altPressed), hwnd, layout,
182 VK_MENU, keyboardState, pause);
183
184 // In order to produce an upper case character, the keyboard state should
185 // be modified. See the documentation of shiftPressed to understand why
186 // it's done only in this case.
187 if ((shiftPressed) || (isShiftPressNeeded(keyCode))) {
188 keyboardState[VK_SHIFT] |= 0x80;
189 }
190
191 keyCode = LOBYTE(keyCode);
192 keyboardState[keyCode] |= 0x80;
193
194 SetKeyboardState(keyboardState);
195
196 LPARAM lparam = generateKeyMessageParam(scanCode, extended);
197
198 pressed = false;
199 if (!PostMessage(hwnd, WM_KEYDOWN, keyCode, lparam)) {
200 LOG(WARN) << "Key down failed: " << GetLastError();
201 }
202
203 PostMessage(hwnd, WM_USER, 1234, 5678);
204
205 // Listen out for the keypress event which IE synthesizes when IE
206 // processes the keydown message. Use a time out, just in case we
207 // have not got the logic right :)
208
209 clock_t maxWait = clock() + 5000;
210 while (!pressed) {
211 wait(5);
212 if (clock() >= maxWait) {
213 LOG(WARN) << "Timeout awaiting keypress: " << keyCode;
214 break;
215 }
216 }
217}
218
219void backgroundKeyUp(HWND hwnd, HKL layout, BYTE keyboardState[256],
220 WORD keyCode, UINT scanCode, bool extended, int pause)

Callers 1

backgroundKeyPressFunction · 0.85

Calls 7

isShiftPressNeededFunction · 0.85
isControlPressNeededFunction · 0.85
isAltPressNeededFunction · 0.85
generateKeyMessageParamFunction · 0.85
waitFunction · 0.85
LOGClass · 0.70

Tested by

no test coverage detected