Algorithm Shutting down PC screen after execution

2

I'm using windows.h in conjunction with C ++, in order to create a routine through the INPUT events. Such as setting the position of the mouse on the screen, clicking and things like that, but every time I perform either function, the screen then goes off (as if it had been missing for a long time), just move the mouse back.

void setMousePos(int posX, int posY){
    INPUT Input;
    Input.type = INPUT_MOUSE;
    Input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;

    Input.mi.dx = posX*(65535.0f/GetSystemMetrics(SM_CXSCREEN));
    Input.mi.dy = posY*(65535.0f/GetSystemMetrics(SM_CYSCREEN));
    SendInput(true,&Input, sizeof(Input));
}

void onClick(){
    INPUT Input;
    Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
    SendInput(true, &Input, sizeof(Input));
    Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
    SendInput(true, &Input, sizeof(Input));
}

It simply performs the functions, and then erases the screen. Some of the Why is the same happening?

The problem is in multiplication by the result of division 65535.0f/GetSystemMetrics(SM_CXSCREEN);

If I run the account with a normal number (1280 for example), everything happens, but when I use a variable (posX for example), it is the cause of the blackout.

  • Operating system: Windows 8.1
  • Language: C ++
  • Library: windows.h
asked by anonymous 14.03.2016 / 02:26

1 answer

2

Problem solved. And thanks to Luiz Vieira for having guided me, and Bacco for helping me.
The solution was to start the INPUT, set it to 0:

setMousePos(int posX, int posY){
    INPUT Input={0} // A resolução do problema foi simples assim
    .......... /Resto do Código
}
    
14.03.2016 / 03:22