I use SendInput () to send relative mouse positions. First, your sick what you do.
I use my finger to move the mouse. So first, I track my finger in a 640x480 image and get the absolute position in pixels with the image.
then I send this position to the next method to generate relative mouse position commands using the send input.
When the finger moves to the left border (xlim1) or the right edge (xlim2), the cursor holds horizontally left or right, depending on which limit. The problem is that when I run the code and only when the cursor starts to move, the screen goes black.
when I comment on the else if (cx> = prevX & cx> xlim2) {....} section, then it works .. (So, when the finger point goes to the right limit of the image, the cursor continues to scroll horizontally to the right. The commented part allows left horizontal scrolling).
The first bool variable will be true, if this is the first time, we fix the finger. Otherwise, this is not true.
void movMouse(int cx, int cy, bool first){ static int prevX = 0; static int prevY = 0; static int leftPrevX; static int rightPrevX; int mx,my; if(first == true){ prevX = cx; prevY = cy; } else{ mx = (cx - prevX); my = (cy - prevY); if(cx <= prevX && cx < xlim1){ mx = -20; INPUT input; input.type = INPUT_MOUSE; input.mi.mouseData = 0; input.mi.dx = -(mx); input.mi.dy = (my); input.mi.dwFlags = MOUSEEVENTF_MOVE; SendInput(1, &input, sizeof(input)); } else if(cx >= prevX && cx > xlim2){ mx = 20; INPUT input; input.type = INPUT_MOUSE; input.mi.mouseData = 0; input.mi.dx = -(mx); input.mi.dy = (my); input.mi.dwFlags = MOUSEEVENTF_MOVE; SendInput(1, &input, sizeof(input)); } else { INPUT input; input.type = INPUT_MOUSE; input.mi.mouseData = 0; input.mi.dx = -(mx); input.mi.dy = (my); input.mi.dwFlags = MOUSEEVENTF_MOVE; SendInput(1, &input, sizeof(input)); } prevX = cx; prevY = cy; }
}
user2389323
source share