0

I need to move the mouse pointer using my finger when i play computer games. (say crysis3.. in this way i will be able to move the camera using my finger).

At the movement I can move the mouse when I am not playing the game. i used SetCursorPos() windows function for this. (movements are nor perfect but that is not a concern.)

But the problem is that this (SetCursorPos) does not has a effect on the game..

Can anyone tel me why and how to solve this??

Thank you.

Lewis Gordon
  • 1,711
  • 14
  • 19
user2389323
  • 769
  • 2
  • 10
  • 22
  • You could try `SendInput`. – chris Jun 22 '13 at 17:13
  • thanks for replying. i am currently using it to invoke mouse clicks.. can it be used to move the mouse as well? – user2389323 Jun 22 '13 at 17:20
  • Yes, as I recall, you have to pass either relative or absolute coordinates, even when clicking. I imagine not passing any flags for clicking would move it. – chris Jun 22 '13 at 17:22
  • Well, it sort of worked for me. With `MOUSEEVENTF_ABSOLUTE | MOUSEEVNTF_MOVE` and coordinate (100, 100), it moved it to (0, 0). Edit: Never mind, I forgot the coordinates are in [0, 65535] for this. The game might like it a bit more than `SetCursorPos`, who knows. – chris Jun 22 '13 at 17:29
  • well i does not work... it works on the game menu. but soon as the game loaded, it stops working. – user2389323 Jun 22 '13 at 18:08

2 Answers2

0

The reason SetCursorPos doesn't work is because the game is likely using a much lower level API to capture the mouse input, probably something like DirectInput.

I suspect that the only way you can intercept that input is with a filter driver. See the answers to this Stack Overflow question: Intercept mouse input

Community
  • 1
  • 1
James Holderness
  • 22,721
  • 2
  • 40
  • 52
  • I tried using RAWINPUT. At the movement i am able to capture mouse position ( relative to the last position )using RAWINPUT in my application. But that is not what i want. i want to give the relative position and change the cursor position according to that. But i do not know how to change it. I tried to use direct input. but the same happen. i could not figure out how to load the position and send it the system. – user2389323 Jun 23 '13 at 08:47
  • As I said, I think you'll need to create a filter driver. Have a look at the moufltr sample in the [DDK](http://msdn.microsoft.com/en-us/library/windows/hardware/gg487428.aspx). – James Holderness Jun 23 '13 at 11:16
0

Finally i was able to get it to work.... :)

SendInput() worked

    mx = (cordi[0][0]) * screenWidth / (640);
    my = (cordi[0][1]) * screenHeight / (480);

    INPUT input;
    input.type  = INPUT_MOUSE;
    input.mi.mouseData  = 0;
    input.mi.dx = -(mx - prevX);//65536 - ((mx - prevX) *(65536/GetSystemMetrics(SM_CXSCREEN)));//x being coord in pixels
    input.mi.dy =  (my - prevY);//(my - prevY) *(65536/GetSystemMetrics(SM_CYSCREEN));//y being coord in pixels
    input.mi.dwFlags    =  MOUSEEVENTF_MOVE;//MOUSEEVENTF_ABSOLUTE
    SendInput(1,&input,sizeof(input));

First time i used MOUSEEVENTF_ABSOLUTE.. it didn't work.. but then i used relative movement just on a hunch and it worked...

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
user2389323
  • 769
  • 2
  • 10
  • 22