Skip to content

Commit

Permalink
Updating IE to handle mouse clicks with "swapped" mouse buttons
Browse files Browse the repository at this point in the history
Fixes issue #6898.
  • Loading branch information
jimevans committed Feb 6, 2019
1 parent 64320c7 commit f59211f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cpp/iedriver/ActionSimulators/SendInputActionSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ int SendInputActionSimulator::SimulateActions(BrowserHandle browser_wrapper,
HookProcessor mouse_hook;
mouse_hook.Initialize("MouseHookProc", WH_MOUSE);

bool is_button_swapped = ::GetSystemMetrics(SM_SWAPBUTTON) != 0;

HWND window_handle = browser_wrapper->GetContentWindowHandle();
// Loop through all of the input items, and find all of the sleeps.
std::vector<size_t> sleep_indexes;
Expand All @@ -75,6 +77,15 @@ int SendInputActionSimulator::SimulateActions(BrowserHandle browser_wrapper,
&normalized_y);
current_input.mi.dx = normalized_x;
current_input.mi.dy = normalized_y;

// If the buttons are swapped on the mouse (most often referred to
// as "left-handed"), where the right button is primary and the
// left button is secondary, we need to swap those when using
// SendInput.
unsigned long normalized_flags = this->NormalizeButtons(is_button_swapped,
current_input.mi.dwFlags);

current_input.mi.dwFlags = normalized_flags;
inputs[i] = current_input;
}
}
Expand Down Expand Up @@ -148,6 +159,30 @@ void SendInputActionSimulator::GetNormalizedCoordinates(HWND window_handle,
*normalized_y = static_cast<int>(cursor_position.y * (65535.0f / screen_height));
}

unsigned long SendInputActionSimulator::NormalizeButtons(bool is_button_swapped,
unsigned long input_flags) {
unsigned long flags = input_flags;
if (is_button_swapped) {
if (flags & MOUSEEVENTF_LEFTDOWN) {
flags &= ~(MOUSEEVENTF_LEFTDOWN);
flags |= MOUSEEVENTF_RIGHTDOWN;
}
else if (flags & MOUSEEVENTF_LEFTUP) {
flags &= ~(MOUSEEVENTF_LEFTUP);
flags |= MOUSEEVENTF_RIGHTUP;
}
else if (flags & MOUSEEVENTF_RIGHTDOWN) {
flags &= ~(MOUSEEVENTF_RIGHTDOWN);
flags |= MOUSEEVENTF_LEFTDOWN;
}
else if (flags & MOUSEEVENTF_RIGHTUP) {
flags &= ~(MOUSEEVENTF_RIGHTUP);
flags |= MOUSEEVENTF_LEFTUP;
}
}
return flags;
}

bool SendInputActionSimulator::WaitForInputEventProcessing(int input_count) {
LOG(TRACE) << "Entering InputManager::WaitForInputEventProcessing";
// Adaptive wait. The total wait time is the number of input messages
Expand Down
2 changes: 2 additions & 0 deletions cpp/iedriver/ActionSimulators/SendInputActionSimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class SendInputActionSimulator : public ActionSimulator {
int y,
int* normalized_x,
int* normalized_y);
unsigned long NormalizeButtons(bool is_button_swapped,
unsigned long input_flags);

bool WaitForInputEventProcessing(int input_count);
bool SetFocusToBrowser(BrowserHandle browser_wrapper);
Expand Down

0 comments on commit f59211f

Please sign in to comment.