473,700 Members | 2,693 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 3607
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
32638
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
17307
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 so that I don't have to wait for the next mouse event before the cursor gets repainted. (2) Why...
10
18075
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 mouse coordinates echoed above.
1
1681
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 the system level. Thanks in advance.
13
2302
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 getting better with practice, the frustration level is high for him as a result of this (he gets very...
5
3718
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 a check box on it, and if the user clicks over the checkbox to drag the user control, the check...
3
4961
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
3134
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 important that I stop these "false" mouseup's from firing or distinguish them from when I let go of...
5
2326
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 enough to be able to move the mouse so that it appears to be in sync with the movement on the client...
0
8648
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9078
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8974
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
6563
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5903
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4407
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4660
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3094
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
3
2031
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.