PC Review


Reply
Thread Tools Rate Thread

advice on sending mouse movement, clicks to a minimized window

 
 
garyusenet@myway.com
Guest
Posts: n/a
 
      19th Dec 2006
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-

 
Reply With Quote
 
 
 
 
garyusenet@myway.com
Guest
Posts: n/a
 
      19th Dec 2006
Just to clarify the program i want to start minimized is the C++
executable.

TIA Gary-

 
Reply With Quote
 
garyusenet@myway.com
Guest
Posts: n/a
 
      19th Dec 2006
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-

 
Reply With Quote
 
Lucian Wischik
Guest
Posts: n/a
 
      19th Dec 2006
(E-Mail Removed) 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.mouseData1=0;mi.dwFlags1=0;mi.time1=0;mi.dwExtraInfo1=IntPtr.Zero;

mi.type2=INPUT_MOUSE;mi.dx2=0;mi.dy2=0;mi.mouseData2=0;mi.dwFlags2=0;mi.time2=0;mi.dwExtraInfo2=IntPtr.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.dll")]
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sockets for sending/receiving mouse movement hurricane_number_one@yahoo.com Microsoft VB .NET 4 12th Aug 2008 05:23 PM
Detect mouse movement from minimized application squeak Microsoft VB .NET 3 20th Sep 2006 11:25 AM
problems in sending mouse clicks via SendInput API kumar_subrahmanya Microsoft VC .NET 2 4th Jul 2006 09:44 AM
Mouse pointer movement causes HELP window to open jolio@webmail.co.za Windows XP Help 3 26th Mar 2005 12:51 PM
How to Prevent Mouse Movement and Clicks From Reaching Control Charles Law Microsoft VB .NET 5 13th Apr 2004 01:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:38 AM.