Unable to control mouse events
-
I am attempting to control mouse events, like moving the mouse and pressing any mouse key ... I am using the following code to set the mouse position as (0,0)
LPINPUT i;
MOUSEINPUT mi;
mi.dx=0;
mi.dy=0;
mi.dwFlags=MOUSEEVENTF_LEFTDOWN;
mi.time=0;
mi.dwExtraInfo=GetMessageExtraInfo();
mi.mouseData=0;
i[0].mi=mi;
i[0].type=INPUT_MOUSE;
SendInput(1,i,sizeof(i));But, I am getting an exception at the line
i[0].mi=mi;
Actually I want to control the mouse pointer through an external hardware, which will be connected at the serial port. I will read the data from the serial port like mouse movement and any mouse key being pressed, then SET this mouse status to the system mouse ....this is my ultimate aim ... So I wrote the above code to set the mouse position first, but its not working ... Please someone help me here ...Apurv A man is but the product of his thoughts. What he thinks, he becomes. .......Mahatma Gandhi Be the change you want to see in the world. .......Mahatma Gandhi
-
I am attempting to control mouse events, like moving the mouse and pressing any mouse key ... I am using the following code to set the mouse position as (0,0)
LPINPUT i;
MOUSEINPUT mi;
mi.dx=0;
mi.dy=0;
mi.dwFlags=MOUSEEVENTF_LEFTDOWN;
mi.time=0;
mi.dwExtraInfo=GetMessageExtraInfo();
mi.mouseData=0;
i[0].mi=mi;
i[0].type=INPUT_MOUSE;
SendInput(1,i,sizeof(i));But, I am getting an exception at the line
i[0].mi=mi;
Actually I want to control the mouse pointer through an external hardware, which will be connected at the serial port. I will read the data from the serial port like mouse movement and any mouse key being pressed, then SET this mouse status to the system mouse ....this is my ultimate aim ... So I wrote the above code to set the mouse position first, but its not working ... Please someone help me here ...Apurv A man is but the product of his thoughts. What he thinks, he becomes. .......Mahatma Gandhi Be the change you want to see in the world. .......Mahatma Gandhi
-
LPINPUT i; LPINPUT means pointer to structure INPUT. Here i is of type LPINPUT. You have to allocate memory for this before you use this variable. ie LPINPUT i = new INPUT;
akt
oh ... thanks ... its not giving anymore errors ... but the mouse position is not set .... here is my updated code ...
LPINPUT i = new INPUT;
MOUSEINPUT mi;
mi.dx=0;
mi.dy=0;
mi.dwFlags=MOUSEEVENTF_MOVE;
mi.time=0;
mi.dwExtraInfo=GetMessageExtraInfo();
mi.mouseData=0;
i[0].mi=mi;
i[0].type=INPUT_MOUSE;
SendInput(1,i,sizeof(i));Apurv A man is but the product of his thoughts. What he thinks, he becomes. .......Mahatma Gandhi Be the change you want to see in the world. .......Mahatma Gandhi
-
oh ... thanks ... its not giving anymore errors ... but the mouse position is not set .... here is my updated code ...
LPINPUT i = new INPUT;
MOUSEINPUT mi;
mi.dx=0;
mi.dy=0;
mi.dwFlags=MOUSEEVENTF_MOVE;
mi.time=0;
mi.dwExtraInfo=GetMessageExtraInfo();
mi.mouseData=0;
i[0].mi=mi;
i[0].type=INPUT_MOUSE;
SendInput(1,i,sizeof(i));Apurv A man is but the product of his thoughts. What he thinks, he becomes. .......Mahatma Gandhi Be the change you want to see in the world. .......Mahatma Gandhi
Try this
INPUT i;
MOUSEINPUT mi;
mi.dx=0;
mi.dy=0;
mi.dwFlags=MOUSEEVENTF_MOVE;
mi.time=0;
mi.dwExtraInfo=GetMessageExtraInfo();
mi.mouseData=0;
i.mi=mi;
i.type=INPUT_MOUSE;
SendInput(1, &i, sizeof(i));«_Superman_» I love work. It gives me something to do between weekends.
-
oh ... thanks ... its not giving anymore errors ... but the mouse position is not set .... here is my updated code ...
LPINPUT i = new INPUT;
MOUSEINPUT mi;
mi.dx=0;
mi.dy=0;
mi.dwFlags=MOUSEEVENTF_MOVE;
mi.time=0;
mi.dwExtraInfo=GetMessageExtraInfo();
mi.mouseData=0;
i[0].mi=mi;
i[0].type=INPUT_MOUSE;
SendInput(1,i,sizeof(i));Apurv A man is but the product of his thoughts. What he thinks, he becomes. .......Mahatma Gandhi Be the change you want to see in the world. .......Mahatma Gandhi
Please check the last parameter of SendInput(); It requires the size of structure INPUT. For this you have call sizeof(INPUT). In your code, you have taken sizeof(i). i means LPINPUT. As i said earlier LPINPUT is a pointer. So sizeof(i) will return the size of a pointer variable only(4 bytes).
akt
-
Try this
INPUT i;
MOUSEINPUT mi;
mi.dx=0;
mi.dy=0;
mi.dwFlags=MOUSEEVENTF_MOVE;
mi.time=0;
mi.dwExtraInfo=GetMessageExtraInfo();
mi.mouseData=0;
i.mi=mi;
i.type=INPUT_MOUSE;
SendInput(1, &i, sizeof(i));«_Superman_» I love work. It gives me something to do between weekends.
its working ... superman .... thank you very much .... will this SendInput() function work outside the application window ? I mean, while i interface it with my hardware, so that the key inputs are coming from the hardware, know suppose the mouse is over the start button, and i send the Left-button pressed event to the SendInput() function ... will this result the Start button being pressed ???
Apurv A man is but the product of his thoughts. What he thinks, he becomes. .......Mahatma Gandhi Be the change you want to see in the world. .......Mahatma Gandhi
-
its working ... superman .... thank you very much .... will this SendInput() function work outside the application window ? I mean, while i interface it with my hardware, so that the key inputs are coming from the hardware, know suppose the mouse is over the start button, and i send the Left-button pressed event to the SendInput() function ... will this result the Start button being pressed ???
Apurv A man is but the product of his thoughts. What he thinks, he becomes. .......Mahatma Gandhi Be the change you want to see in the world. .......Mahatma Gandhi
I believe that it will work where ever the mouse pointer is located.
«_Superman_» I love work. It gives me something to do between weekends.