473,573 Members | 2,920 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.e xe"

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 3600
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********@mywa y.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 SetWindowPositi on,
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(G WL_EXSTYLE)
to give it WS_EX_TOOLWINDO W.

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(S ystem.Runtime.I nteropServices. LayoutKind.Sequ ential)]
public struct MOUSEINPUT
{ public static MOUSEINPUT Zero()
{ MOUSEINPUT mi;

mi.type1=INPUT_ MOUSE;mi.dx1=0; mi.dy1=0;mi.mou seData1=0;mi.dw Flags1=0;mi.tim e1=0;mi.dwExtra Info1=IntPtr.Ze ro;

mi.type2=INPUT_ MOUSE;mi.dx2=0; mi.dy2=0;mi.mou seData2=0;mi.dw Flags2=0;mi.tim e2=0;mi.dwExtra Info2=IntPtr.Ze ro;
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_LEF TDOWN=0x0002;
const Int32 MOUSEEVENTF_LEF TUP = 0x0004;
const Int32 MOUSEEVENTF_ABS OLUTE = 0x8000;
[System.Runtime. InteropServices .DllImport("use r32.dll")]
public static extern UInt32 SendInput(UInt3 2 nInputs, ref MOUSEINPUT
pInputs, Int32 cbSize);
public Form1()
{ InitializeCompo nent();
}

private void button2_Click(o bject sender,EventArg s e)
{ MessageBox.Show ("click2");
}

int state=1;

private void button1_Click(o bject sender,EventArg s e)
{ state=1;
}

private void timer1_Tick(obj ect sender,EventArg s e)
{ if (state==0) return;
MOUSEINPUT mi = MOUSEINPUT.Zero ();
if (state==1)
{ Point pt=new Point(button2.W idth/2,button2.Heigh t/2),
oldpos=Cursor.P osition;
Cursor.Position = button2.PointTo Screen(pt);
mi.dwFlags1=MOU SEEVENTF_LEFTDO WN;
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=MOU SEEVENTF_LEFTUP ; uint
r=SendInput(1,r ef 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
32619
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 mouse click and the button under the mouse is clicked. Yours, Jonas
3
17294
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 seems to be ignored completely, even when I try with window.setTimeout. So my two questions are: (1) Most important: Is there anything I can do...
10
18047
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 I've Googled so much my brain hurts. http://www.ghpkendal.co.uk/TestPages/Test.htm Move your cursor over the yellow area and you should see the...
1
1671
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. So the application is not loaded and visible, so mouse movements on the form won't work, I need the program to be able to detect mouse movement on...
13
2287
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 well. He is frequently missing the left mouse button and hitting the right, or less often the middle (wheel) buttons. While he is very slowly...
5
3692
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 onto a form in my application when it is running. I allow it to be clicked and dragged to a new location on the form. However, the user control has...
3
4951
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 when my application is just minimized and not the active forground app. I only need to triger an event which is going to tell my app if the
2
3122
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 same column then mouseup anywhere in a cell. The mouseup event sometimres fires before the selection of table cells by dragging is complete. It's...
5
2315
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 display. I have this basic part working. The problem is that response time is really bad. It seems like the server is not receiving the data fast...
0
7767
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8006
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7768
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8058
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6400
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5288
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3729
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2191
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 we have to send another system
0
1035
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.