3
I am using windows. h in conjunction with C++, for the purpose of creating a routine through INPUT events. Such as setting the mouse position on the screen, clicking and things like that, but every time I run any of the two functions, the screen then erases (as if it had been away for a long time), as just move the mouse it comes 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 occurring the same?
The problem is multiplication by the result of division 65535.0f/GetSystemMetrics(SM_CXSCREEN);
If I run the account with a normal number (1280 for example), everything goes well, but when I use a variable (posX for example), it is the cause of the blackout.
- Operating System: Windows 8.1
- Parlance: C++
- Library: windows. h
I found that in reality, the problem is not the division, but the multiplication made after obtaining the result of the division. However, if I run the account with normal numbers, there is no problem, for example: Input.mi.dy = 800*(65535.0f/Getsystemmetrics(SM_CYSCREEN));. But if instead of the 800 I use a variable, this will cause the blackout.
– Felipe Chiarotti
I’ve solved the problem for now. Instead of creating an INPUT every time I ran the function, I put it to pass as argument: void setMousePos(int posX, int Posy, INPUT& Input). This way I start the same in the main function.
– Felipe Chiarotti
You can reset the whole structure by creating the INPUT. The important thing is, for example, how you don’t use x and y in the click, reset them in the click function. The members you do not use in the move, zere in the move function, and so on. It’s easier for you to reset the whole structure when creating the input, which is relatively simple. That’s not just true for this case. Whenever you use such a structure, be sure to have it cleaned;
– Bacco
Hello, I’m glad you fixed the problem. But, if so, please create yourself an answer detailing your solution (and mark it as accepted). Do not edit the question to include the solution, Because this site is not a forum. If you haven’t already, please read [help]. :)
– Luiz Vieira
You almost created your first virus, you can send it to your friends to disturb them :) - Joking aside, good that you managed to solve, I recommend that you post the function "whole" as it was.
– Guilherme Nascimento