473,399 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

advice on sending mouse movement, clicks to a minimized window

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 keystrokes to the programme, and mouse strokes.

Can you please tell me how I would do this assuming the programme is
called "c:\programme.exe"

What i need to do is :
launch the programme, move the mouse to a certain position, click,
enter some keyboard strokes, press enter, then move the mouse, click
again.

*Also one other thing that i would like to know is if it is possible to
start the programme and not list it as running on the taskbar.

Thanks!

Gary-

Dec 19 '06 #1
3 3591
Just to clarify the program i want to start minimized is the C++
executable.

TIA Gary-

Dec 19 '06 #2
Just to further clarify - i would like to complete all the mouse
movement, and keyboard strokes while the program is minimized / not
visible.

And for future reference I will re read my post a number of times, so i
dont repeat this process of having to clarify my original post twice!

Thankyou,

Gary-

Dec 19 '06 #3
ga********@myway.com wrote:
>launch the programme, move the mouse to a certain position, click,
enter some keyboard strokes, press enter, then move the mouse, click
again.
This is a difficult task.

To launch the program, use Process.Start

Instead of running minimized, I think you should try repositioning it
offscreen. I'd try interop with the win32 function SetWindowPosition,
but maybe there's a way to do it in .net. This function can also hide
it. But some applications might behave differently if they're
hidden/minimized, which is why that might not work. Another way to
hide it from the taskbar is win32 function GetWindowLong(GWL_EXSTYLE)
to give it WS_EX_TOOLWINDOW.

To find its window, I've used interop with the win32 function
"FindWindow". And I've used this to navigate down to the appropriate
dialogs/windows.

To enter keyboard strokes and click buttons, it's nicer instead if you
post the appropriate messages direct to the controls. To learn which
messages to send where, you should read a lot of MSDN about common
controls and their messages, eg. BN_CLICKED and EM_SETTEXT and so on.
There's a lot of reading for you to do. I don't know the .net calls
for sending messages to a window. You could use interop with
PostMessage.
Otherwise, if those aren't working, you can spoof mouse movement and
keyboard strokes at a lower level. This is a worse solution, more
clunky, so avoid it if possible. Here's some example code to get you
started.
[System.Runtime.InteropServices.StructLayout(System .Runtime.InteropServices.LayoutKind.Sequential)]
public struct MOUSEINPUT
{ public static MOUSEINPUT Zero()
{ MOUSEINPUT mi;

mi.type1=INPUT_MOUSE;mi.dx1=0;mi.dy1=0;mi.mouseDat a1=0;mi.dwFlags1=0;mi.time1=0;mi.dwExtraInfo1=IntP tr.Zero;

mi.type2=INPUT_MOUSE;mi.dx2=0;mi.dy2=0;mi.mouseDat a2=0;mi.dwFlags2=0;mi.time2=0;mi.dwExtraInfo2=IntP tr.Zero;
return mi;
}
public int Size() {return (int)Count()*28;}
public UInt32 Count() {if (dwFlags2!=0) return 2; else if
(dwFlags1!=0) return 1; else return 0;}
public Int32 type1, dx1,dy1, mouseData1, dwFlags1, time1; public
IntPtr dwExtraInfo1;
public Int32 type2, dx2,dy2, mouseData2, dwFlags2, time2; public
IntPtr dwExtraInfo2;
}
const Int32 INPUT_MOUSE=0;
const Int32 MOUSEEVENTF_LEFTDOWN=0x0002;
const Int32 MOUSEEVENTF_LEFTUP = 0x0004;
const Int32 MOUSEEVENTF_ABSOLUTE = 0x8000;
[System.Runtime.InteropServices.DllImport("user32.d ll")]
public static extern UInt32 SendInput(UInt32 nInputs, ref MOUSEINPUT
pInputs, Int32 cbSize);
public Form1()
{ InitializeComponent();
}

private void button2_Click(object sender,EventArgs e)
{ MessageBox.Show("click2");
}

int state=1;

private void button1_Click(object sender,EventArgs e)
{ state=1;
}

private void timer1_Tick(object sender,EventArgs e)
{ if (state==0) return;
MOUSEINPUT mi = MOUSEINPUT.Zero();
if (state==1)
{ Point pt=new Point(button2.Width/2,button2.Height/2),
oldpos=Cursor.Position;
Cursor.Position = button2.PointToScreen(pt);
mi.dwFlags1=MOUSEEVENTF_LEFTDOWN;
uint r=SendInput(mi.Count(), ref mi, mi.Size());
if (r==mi.Count()) Console.Beep();
state=3; return;
}
if (state==3)
{ mi.dx1=0; mi.dy1=0; mi.dwFlags1=MOUSEEVENTF_LEFTUP; uint
r=SendInput(1,ref mi, mi.Size());
if (r==1) Console.Beep();
state=0; return;
}
}
--
Lucian
Dec 19 '06 #4

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

Similar topics

10
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...
3
by: Csaba2000 | last post by:
I have set onmousedown to change the cursor, but this setting is ignored (IE 5.5; NN 6.1 on Win 2K Pro) until the mouse is either moved or the mouse button is released. On Opera 7.01, the setting...
10
by: Danny | last post by:
How can I get the coordinates of the mouse cursor in Mozilla browsers as well as Opera and IE6? I'm struggling to understand how to capture mouse movement events with Mozilla/Netscape/Firefox and...
1
by: John | last post by:
Hi all: I have an application that hides itself and displays an icon in the system tray. Is it possible for this application to detect keystrokes and/or mouse movements while hidden/minimized....
13
by: James Bond | last post by:
Hello. My 80+ year old father has recently decided to get his first computer. Due to his age (and I suspect lack of playing pong as a child like I did) he lacks the manual dexterity to use a mouse...
5
by: Charles Law | last post by:
Sorry for reposting this question, but I did not get a single answer last time, and I'm sure you guys must have some thoughts on the matter. I have a user control which can be dragged and dropped...
3
by: squeak | last post by:
Hi there, I'm new to VB2005 so its probably a very simple answer too! But i just can't think how to do it... Basically i need to detect mouse (and preferably keyboard) movement and kepresses...
2
by: markszlazak | last post by:
In the following script, a control displays (black box) in each table cell once you mouse over the cell. Mouse down on the control to change the mode of the table. Drag the mouse over cells in the...
5
by: hurricane_number_one | last post by:
I am creating a simple server application, that will listen for incoming mouse coordinates and then move the mouse accordingly. So basically it's like a very simple VNC server without and screen...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.