473,508 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems sending mouse inputs using SendInput


Hi,
I am facing problems in sending mouse clicks via SendInput API.

Mouse clicks are being sent but at the X,Y co-ordinates.

I am mapping my monitor to the (0,0,65535,65535) virtual monitor as
needed by the SendInput. But the mouse clicks are always reported at
the "current cursor location" (I am testing it with the notepad)
irrespective of the X,Y co-ordinates specified.

Here is the code.
void SendMouseInput(unsigned int iX,unsigned int iY)
{
MOUSEINPUT mousei={0};
INPUT Input={0};
BlockInput(true);
::ZeroMemory(&Input,sizeof(INPUT));
::ZeroMemory(&mousei,sizeof(MOUSEINPUT));
mousei.dx=VirtualXFromAbsoluteX(iX);
mousei.dy=VirtualYFromAbsoluteY(iY);
mousei.dwFlags=MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_LE FTDOWN;
Input.type = INPUT_MOUSE;
Input.mi = mousei;

if(::SendInput(1,&Input,sizeof(Input))==0)
ShowError("SendMouseInput");
mousei.dwFlags=MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_LE FTUP;
Input.type = INPUT_MOUSE;
Input.mi = mousei;

if(::SendInput(1,&Input,sizeof(Input))==0)
ShowError("SendMouseInput");
BlockInput(false);
Sleep(1000);

}
static int VirtualXFromAbsoluteX ( int iX )
{

double Width = GetSystemMetrics ( SM_CXSCREEN ) ;
double Val = ( ((double)iX/Width) * (double)(65535) ) ;

double Ceil = ceil ( Val ) ;
double Floor = floor ( Val ) ;

if ( Ceil > Floor )
{
iX = (int)Ceil ;
}
else
{
iX = (int)Floor ;
}
return ( iX ) ;
}
static int VirtualYFromAbsoluteY ( int iY )
{

double Height = GetSystemMetrics ( SM_CYSCREEN ) ;
double Val = ( ((double)iY/Height) * (double)(65535) ) ;

double Ceil = ceil ( Val ) ;
double Floor = floor ( Val ) ;

if ( Ceil > Floor )
{
iY = (int)Ceil ;
}
else
{
iY = (int)Floor ;
}
return ( iY ) ;
}

void ShowError(LPTSTR lpszFunction)
{
TCHAR szBuf[80];
LPVOID lpMsgBuf;
DWORD dw = GetLastError();

FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );

wsprintf(szBuf,
"%s failed with error %d: %s",
lpszFunction, dw, lpMsgBuf);

::MessageBox(NULL, szBuf, "Error", MB_OK);

LocalFree(lpMsgBuf);
}

Am I doing something wrong?

PS: I am able to send key board events using SendInput.

Thanks a load in advance.

--
kumar_subrahmanya
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Jun 1 '06 #1
1 2313
Hi,

Call SetCursorPos() before calling SendInput().

Hope this helps.

Dinesh Venugopalan

"kumar_subrahmanya" <ku**********************@mail.codecomments.com> wrote
in message news:ku**********************@mail.codecomments.co m...

Hi,
I am facing problems in sending mouse clicks via SendInput API.

Mouse clicks are being sent but at the X,Y co-ordinates.

I am mapping my monitor to the (0,0,65535,65535) virtual monitor as
needed by the SendInput. But the mouse clicks are always reported at
the "current cursor location" (I am testing it with the notepad)
irrespective of the X,Y co-ordinates specified.

Here is the code.
void SendMouseInput(unsigned int iX,unsigned int iY)
{
MOUSEINPUT mousei={0};
INPUT Input={0};
BlockInput(true);
::ZeroMemory(&Input,sizeof(INPUT));
::ZeroMemory(&mousei,sizeof(MOUSEINPUT));
mousei.dx=VirtualXFromAbsoluteX(iX);
mousei.dy=VirtualYFromAbsoluteY(iY);
mousei.dwFlags=MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_LE FTDOWN;
Input.type = INPUT_MOUSE;
Input.mi = mousei;

if(::SendInput(1,&Input,sizeof(Input))==0)
ShowError("SendMouseInput");
mousei.dwFlags=MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_LE FTUP;
Input.type = INPUT_MOUSE;
Input.mi = mousei;

if(::SendInput(1,&Input,sizeof(Input))==0)
ShowError("SendMouseInput");
BlockInput(false);
Sleep(1000);

}
static int VirtualXFromAbsoluteX ( int iX )
{

double Width = GetSystemMetrics ( SM_CXSCREEN ) ;
double Val = ( ((double)iX/Width) * (double)(65535) ) ;

double Ceil = ceil ( Val ) ;
double Floor = floor ( Val ) ;

if ( Ceil > Floor )
{
iX = (int)Ceil ;
}
else
{
iX = (int)Floor ;
}
return ( iX ) ;
}
static int VirtualYFromAbsoluteY ( int iY )
{

double Height = GetSystemMetrics ( SM_CYSCREEN ) ;
double Val = ( ((double)iY/Height) * (double)(65535) ) ;

double Ceil = ceil ( Val ) ;
double Floor = floor ( Val ) ;

if ( Ceil > Floor )
{
iY = (int)Ceil ;
}
else
{
iY = (int)Floor ;
}
return ( iY ) ;
}

void ShowError(LPTSTR lpszFunction)
{
TCHAR szBuf[80];
LPVOID lpMsgBuf;
DWORD dw = GetLastError();

FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );

wsprintf(szBuf,
"%s failed with error %d: %s",
lpszFunction, dw, lpMsgBuf);

::MessageBox(NULL, szBuf, "Error", MB_OK);

LocalFree(lpMsgBuf);
}

Am I doing something wrong?

PS: I am able to send key board events using SendInput.

Thanks a load in advance.

--
kumar_subrahmanya
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Jun 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
32599
by: BadOmen | last post by:
I want my program to send a mouse click to the window at the current mouse position, how do I do that? Example: I have my mouse over a button in Word and then my program is sending the left...
7
3151
by: Dayne | last post by:
How do I send a mouse or keyboard event(vb.net) without touch(using) either? DT
0
1179
by: Trammel | last post by:
Hi. Im trying to make a vb.net aplication click location 200,350 on an window who's name is "Blah" (Not owned/started by my application). This has to be done using SendInput as Im coding it for...
2
2126
by: kumar_subrahmanya | last post by:
Hi, I am facing problems in sending mouse clicks via SendInput API. Mouse clicks are being sent but at the X,Y co-ordinates. I am mapping my monitor to the (0,0,65535,65535) virtual monitor as...
3
3752
by: Morten Snedker | last post by:
If I have a number of random applications open, move the mouse cursor to a given position and do a click, the application gets the focus. That is what this simple code should illustrate: Dim...
18
22046
by: eliss.carmine | last post by:
Is it possible to simulate a mouse click in the window I made (it's a Form), but not give it focus? I tried using WinAPI's mouseevent and SendMessage of WM_LBUTTONDOWN/WM_LBUTTONUP as suggested...
3
3598
by: garyusenet | last post by:
I have a programme written in C++, the programme is unmanaged and is an executable, i don't have any source code. I'm writing a C# program. I want to (a) start the programme minimized. (b) send...
0
1574
by: Andrea | last post by:
Hi I've having a very strange problem using the SendInput API to send text to other applications. I've written the code and it seems to work well. I discovered a strange problem: when I try to...
3
1972
by: Adrian Luck | last post by:
Hi, Is it possible to send mouse left click signals/inputs and keyboard inputs from a flash application to another program?
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.