=)
I am using C++ (not VC++) on windows7 laptop.
I have a problem with this method for moving the mouse x/y from it's current position. Every time it calls send input for a mouse event it moves the mouse but also turns off my screen (the equivalent of Fn+F2). I debugged the program and noticed that not only did mi
but also ki
and hi
had values (this was for x=25, y=25 and absolure=false):
mi:
dx 25
dy 25
mouseData 0
dwFlags 1
time 2686400
dwExtraInfo 0
ki:
wVk 25
wScan 0
dwFlags 25
time 0
dwExtraInfo 1
hi:
uMsg 25
wParamL 25
wParamH 0
I have tried to set ki and hi to 0 but if I do that then mi is also set to 0 and then no mouse moves but the screen is still put to sleep! :$
Here are some of the methods I used.
int Controller::mouse_move(long x, long y, bool absolute) {
mouse.dx = x;
mouse.dy = y;
if (absolute) {
mouse.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
}else{
mouse.dwFlags = MOUSEEVENTF_MOVE;
}
mouse.mouseData = 0;
mouse.dwExtraInfo = 0;
input.type = INPUT_MOUSE;
input.mi = mouse;
SendInput(1, &input, sizeof (input));
return 0;
}
OR
int Controller::mouse_move(long x, long y, bool absolute, int index_vector_no) {
input.type = INPUT_MOUSE;
input.mi.dx = x;
input.mi.dy = y;
if (absolute) {
input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
}else{
input.mi.dwFlags = MOUSEEVENTF_MOVE;
}
input.mi.mouseData = 0;
input.mi.dwExtraInfo = 0;
input.ki.dwExtraInfo = 0;
input.ki.dwFlags = 0;
input.ki.time = 0;
input.ki.wScan = 0;
input.ki.wVk = 0;
input.hi.uMsg = 0;
input.hi.wParamH = 0;
input.hi.wParamL = 0;
SendInput(1, &input, sizeof (input));
return 0;
}
Can anyone thing why this is sending keyboard input as well as mouse?! is it just something to do with my laptop configuration?
Thanks in advance! =)
The reason the others change is because they're all in a union, so they share the same memory.
About the screen turning off, you didn't set mi.time
to 0, so it's uninitialized. It's often a good idea to start initializing these structs to {0}, so you don't forget things. The timestamp becomes some random number, which can cause a timeout on the display.