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

Function mouseMoveTo

cpp/webdriver-interactions/interactions.cpp:845–879  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

843}
844
845LRESULT mouseMoveTo(WINDOW_HANDLE handle, long duration, long fromX, long fromY, long toX, long toY)
846{
847 if (!handle) {
848 LOG(WARN) << "Window handle is invalid";
849 return ENULLPOINTER;
850 }
851
852 pausePersistentEventsFiring();
853
854 HWND directInputTo = (HWND) handle;
855 long pointsDistance = distanceBetweenPoints(fromX, fromY, toX, toY);
856 const int stepSizeInPixels = 5;
857 int steps = pointsDistance / stepSizeInPixels;
858
859 long sleep = duration / max(steps, 1);
860
861 WPARAM buttonValue = (leftMouseButtonPressed ? MK_LBUTTON : 0);
862 if (shiftPressed) {
863 buttonValue |= MK_SHIFT;
864 }
865
866 for (int i = 0; i < steps + 1; i++) {
867 //To avoid integer division rounding and cumulative floating point errors,
868 //calculate from scratch each time
869 int currentX = (int)(fromX + ((toX - fromX) * ((double)i) / steps));
870 int currentY = (int)(fromY + ((toY - fromY) * ((double)i) / steps));
871 SendMessage(directInputTo, WM_MOUSEMOVE, buttonValue, MAKELPARAM(currentX, currentY));
872 wait(sleep);
873 }
874
875 SendMessage(directInputTo, WM_MOUSEMOVE, buttonValue, MAKELPARAM(toX, toY));
876 resumePersistentEventsFiring(directInputTo, toX, toY, buttonValue);
877
878 return 0;
879}
880
881bool pending_input_events()
882{

Callers

nothing calls this directly

Calls 5

distanceBetweenPointsFunction · 0.85
waitFunction · 0.85
LOGClass · 0.70

Tested by

no test coverage detected