3

I want to move my mouse on my screen, I use this code :

#include <windows.h>
int main(int argc, int *argv[]){
    POINT pt;
    GetCursorPos(&pt);
    printf("Current cursor position (%d, %d)\n", pt.x, pt.y);
    pt.x = 100;
    pt.y = 100;
    SetCursorPos(pt.x, pt.y);
    GetCursorPos(&pt);
    printf("Current cursor position (%d, %d)\n", pt.x, pt.y);
    system("pause");
 }

This script works I see that the position changes, but the mouse does not move on the screen. Should I use another function to move cursor ?

Niall
  • 30,036
  • 10
  • 99
  • 142
simon
  • 1,180
  • 3
  • 12
  • 33
  • What was the return value from each of those 2 cursor functions? – Weather Vane Oct 20 '15 at 07:50
  • Really ? you cursor move on the screen ? @machine_1 – simon Oct 20 '15 at 08:08
  • Win8.1, VS2013. The cursor doesn't move. – Niall Oct 20 '15 at 08:17
  • Win7 Ult. VS2010 . The cursor move. – machine_1 Oct 20 '15 at 08:19
  • Win8.1, VS2013. The cursor move – sjsam Oct 20 '15 at 08:28
  • Hum me I use Win7 and VS2015 Comunity – simon Oct 20 '15 at 08:28
  • 1
    The same issue as http://stackoverflow.com/q/22259936/2564301? – Jongware Oct 20 '15 at 08:30
  • My crystal ball says that you confuzzle the cursor of a console mode program with the mouse cursor. Use SetConsoleCursorPosition() instead. – Hans Passant Oct 20 '15 at 08:31
  • Yes I use console mode program but I want move the mouse cursor, I have already seen the function `SetConsoleCursorPosition()` but this function is for move cursor on the console, and me I want move the cursor on the screen – simon Oct 20 '15 at 08:34
  • @simon : Debug or Release build? – sjsam Oct 20 '15 at 08:46
  • @sjasm : Release build why? – simon Oct 20 '15 at 08:47
  • @ Could you try in the debug mode and see if the cursor moves? – sjsam Oct 20 '15 at 08:57
  • @sjasm : No change with debug mode the cursor don't move. it's really strange, I get the position is correct but the visual is not good the cursor don't moves – simon Oct 20 '15 at 08:59
  • If I use the keyboard to move the mouse it works and I use `SetCursorPos()` so why if I use `SetCursorPos()` without keyboard the cursor dont't move it's so strange – simon Oct 20 '15 at 09:12
  • @simon : No means of seeing the return values in the debug mode? – sjsam Oct 20 '15 at 09:21
  • @sjsam : `SetCursorPos()` return BOOL and in my case this BOOL is True. If if I make a `mouse_event()` after `SetCursorPos()` to simulate right click I see that the position is good. It's really a visual problem, the cursor does not move – simon Oct 20 '15 at 09:29
  • 1
    Are you connected to your development machine through a virtualization software, like Remote Desktop or Citrix Receiver? – IInspectable Oct 20 '15 at 12:32
  • Yes this is virtualization and I think that's problematic, because if I'm on a machine "normal" my cursor move. And for this I use `mouse_event(MOUSEEVENTF_MOVE, x, y)`. This function operates on "normal" machine but It doesn't work virtualized machines (VMware) – simon Oct 20 '15 at 12:49

0 Answers0