472,780 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 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 34501
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.