-
November 27th, 2016, 08:33 PM
#1
sendinput event
this is my code:
I am trying to make it do a right mouse button down and drag and then at the end of the drag, let go of the right mouse button. For some reason it doesn't work! It's for my project to control a video game mouse look event. I am trying to make it turn right by so and so degrees.
Did I do something wrong here?
thx!
Code:
INPUT input;
input.type = INPUT_MOUSE;
input.mi.dx = 0;
input.mi.dy = 0;
input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
input.mi.time = 10;
input.mi.time = 0;
SendInput(1, &input, sizeof(input));
Sleep(50);
input.type = INPUT_MOUSE;
input.mi.dx = 100;
input.mi.dy = 0;
input.mi.dwFlags = MOUSEEVENTF_MOVE;
input.mi.time = 10;
SendInput(1, &input, sizeof(input));
Sleep(50);
input.type = INPUT_MOUSE;
input.mi.dx = 0;
input.mi.dy = 0;
input.mi.dwFlags = MOUSEEVENTF_RIGHTUP;
input.mi.time = 0;
SendInput(1, &input, sizeof(input));
-
November 27th, 2016, 09:08 PM
#2
Re: sendinput event
Pass in an array of INPUT structs and make a single call to SendInput().
-
November 28th, 2016, 12:00 PM
#3
Re: sendinput event
I don't know how to do that, could you show me up please?
-
November 28th, 2016, 07:21 PM
#4
Re: sendinput event
Have you tried mouse_event instead ? Simulate click down then move pointer and simulate click up
Code:
// Bring Window On Top
HWND window = FindWindow(NULL, "Window Title");
ShowWindow(window, SW_RESTORE);
SetForegroundWindow(window);
// Rect Location
RECT rect;
GetWindowRect(window, &rect);
// Set Cursor
SetCursorPos(rect.right - 50, rect.bottom - 100);
// Click once
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
// Set Cursor Second Location
SetCursorPos(rect.right - 100, rect.bottom - 200);
// Release click
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
I had cases when sendinput failed but mouse_event didn't
Last edited by eclessiastes; November 28th, 2016 at 07:28 PM.
-
November 28th, 2016, 07:32 PM
#5
Re: sendinput event
that works alright, if i give the 3 commands separately yes, but it's different from giving all 3 commands in one sendinput, i dont know why. That's why i am trying to figure it out
-
November 28th, 2016, 09:08 PM
#6
Re: sendinput event
probably because u use the same INPUT input. you could do INPUT input1 for one task, INPUT input2 for another etc. I had cases when SendInput didn't work for virtualized exe in different session id, since then i always use mouse_event
Last edited by eclessiastes; November 28th, 2016 at 09:11 PM.
-
November 29th, 2016, 01:29 AM
#7
Re: sendinput event
When you pass the array of items, you need to set input.mi.time to an increasing value for each of the array entries.
-
November 29th, 2016, 05:49 PM
#8
Re: sendinput event
Originally Posted by Arjay
When you pass the array of items, you need to set input.mi.time to an increasing value for each of the array entries.
how long?
This is what I have now, but it seems there is some problem with building the array. I get this error message:
argument of type "INPUT (*)[3]" is incompatible with parameter of type "LPINPUT"
Code:
#include <iostream>
#include <windows.h>
#include <ctime>
using namespace std;
void main()
{
Sleep(3000);
INPUT input[3];
input[0].type = INPUT_MOUSE;
input[0].mi.dx = 0;
input[0].mi.dy = 0;
input[0].mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
input[0].mi.time = 10;
input[1].type = INPUT_MOUSE;
input[1].mi.dx = 100;
input[1].mi.dy = 0;
input[1].mi.dwFlags = MOUSEEVENTF_MOVE;
input[1].mi.time = 10;
input[2].type = INPUT_MOUSE;
input[2].mi.dx = 0;
input[2].mi.dy = 0;
input[2].mi.dwFlags = MOUSEEVENTF_RIGHTUP;
input[2].mi.time = 0;
SendInput(3, &input, sizeof(input));
return;
}
-
November 29th, 2016, 06:50 PM
#9
Re: sendinput event
Try
Code:
INPUT input[3] = {0};
input[0].type = INPUT_MOUSE;
input[0].mi.dx = 0;
input[0].mi.dy = 0;
input[1].mi.time = GetTickCount();
input[0].mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
input[1].type = INPUT_MOUSE;
input[1].mi.dx = 100;
input[1].mi.dy = 0;
input[1].mi.time = GetTickCount();
input[1].mi.dwFlags = MOUSEEVENTF_MOVE;
input[2].type = INPUT_MOUSE;
input[2].mi.dx = 0;
input[2].mi.dy = 0;
input[1].mi.time = GetTickCount();
input[2].mi.dwFlags = MOUSEEVENTF_RIGHTUP;
SendInput(3, &input, sizeof(INPUT));
}
Also, search this forum for SendInput and bing or google for "SendInput Examples C++".
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|