473,387 Members | 1,892 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,387 software developers and data experts.

simulate mouse movements and click operations in c#

Hi.
How to simulate(automatic) mouse movements and click operation using c#.
Actually, i got pixels in the face (face tracking) right now and i need to move mouse(automatically, without using mouse manually) i.e., simulate mouse click operation using those pixels in c#.
I think we can use robot() class in java , to achieve this, but how can we do this using c#.
Hope you understand my problem and get bck to me asap.


thanx
bye
Jun 14 '06 #1
3 34692
Hi.
How to simulate(automatic) mouse movements and click operation using c#.
Actually, i got pixels in the face (face tracking) right now and i need to move mouse(automatically, without using mouse manually) i.e., simulate mouse click operation using those pixels in c#.
I think we can use robot() class in java , to achieve this, but how can we do this using c#.
Hope you understand my problem and get bck to me asap.


thanx
bye

Have find the solution of your problem.
Actually i am facing the same problem now a days.
Pls tell me if you find the solution.
My email id is khaleek_ahmad@yahoo.com
Thanks in Advance
Mar 6 '07 #2
Sejton
1
using System;
using System.Runtime.InteropServices;
...


// usingAPI for mouse governing and other possibilities

#region Подключение API для управления мышкой и других возможностей



enum Messages{WM_LBUTTONDOWN = 0x0201, WM_LBUTTONUP = 0x0202};
const int MK_LBUTTON = 0x0001;
[DllImport("User32.dll")]
static extern int SendMessage(IntPtr hWnd, Messages uMsg, int wParam, IntPtr lParam);

//импортируем mouse_event():
[DllImport("User32.dll")]
static extern void mouse_event(MouseFlags dwFlags, int dx, int dy, int dwData, UIntPtr dwExtraInfo);
//для удобства использования создаем перечисление с необходимыми флагами (константами), которые определяют действия мыши:
//as a matter of convenience, use create enumeration with necessary flags (constants), which define actions of mouse:

[Flags]
enum MouseFlags
{
Move = 0x0001, LeftDown = 0x0002, LeftUp = 0x0004, RightDown = 0x0008,
RightUp = 0x0010, Absolute = 0x8000};
/// <summary>
/// Кликнуть в какомто месте экрана
///Click In some place of screen
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
private void TestMouse(int x, int y)
{

mouse_event(MouseFlags.Absolute | MouseFlags.Move, x, y, 0, UIntPtr.Zero);
mouse_event(MouseFlags.Absolute | MouseFlags.LeftDown , x, y, 0, UIntPtr.Zero);
mouse_event(MouseFlags.Absolute | MouseFlags.LeftUp, x, y, 0, UIntPtr.Zero);

}



#endregion
Mar 6 '07 #3
Hai friend,
use the code below to simulate mouse click
Expand|Select|Wrap|Line Numbers
  1. using System.Runtime.InteropServices;
  2.  
  3. private const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
  4. private const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;
  5. [DllImport("user32.dll")]
  6.         private static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, uint dwExtraInf);
  7. private void btnSet_Click(object sender, EventArgs e)
  8.         {
  9.             int x = Convert.ToInt16(txtX.Text);//set x position 
  10.             int y = Convert.ToInt16(txtY.Text);//set y position 
  11.             Cursor.Position = new Point(x, y);
  12.             mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);//make left button down
  13.             mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);//make left button up
  14.         }
  15.  
txtX is a text box to set x position of cursor
txtY is a text box to set y position of cursor
btnSet is a a button
when yo clicks on the button btnset the cursor will move to the position specified in two text boxes(txtX & txtY)
Jan 3 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jonny | last post by:
Hi all, Does anyone know how to capture the Windows Keys (I know that they are out of the ascii key range) and how to capture and record Mouse movements? Thanks, /Jonny
4
by: Harry J. Smith | last post by:
How can you detect a mouse double click on a text box? I tried the following but it does not work. private void richTextOut_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) //...
1
by: Sakharam Phapale | last post by:
Hi All, How to capture Mouse Single click and mouse double click event on Commnad Button. I am doing as follows. Private void Button1_MouseUp(Object sender,...
3
by: cover | last post by:
Is it possible to use a 'mouse up' click in forms where if you have for example, a drop down menu where you might click as the top selection, an equipment area (hard coded into the form), the type...
4
by: Abhishek | last post by:
Hi, I have a activex web browser embedded in a windows form and on a click of a form button i need the mouse to go the position for example 100, 100 and click the link that will be there on that...
7
by: Steve | last post by:
How do you disable the mouse right click to prevent pop-up window? Or if I want to have cut/copy/paste on pop-up window use same code as my custom cut/copy/paste that are triggered by toolstrip...
2
by: DanAusitn | last post by:
Good morning folk, a quick question to anyone who can help. i am working on a program and i am using the below code to simulate mouse movement to certain co-ords, but the thing is the...
1
by: sahani | last post by:
how do i create a programme to capture mouse movements?? and i want to write something using mouse pointer during the presentation? and what are the ways to implement software to capture mouse...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...

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.