| 843 | } |
| 844 | |
| 845 | LRESULT 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 | |
| 881 | bool pending_input_events() |
| 882 | { |
nothing calls this directly
no test coverage detected