Click here to Skip to main content
15,914,820 members
Home / Discussions / C#
   

C#

 
QuestionThousands of remote message queues - possible? Pin
jenspa8-Nov-07 23:46
jenspa8-Nov-07 23:46 
AnswerRe: Thousands of remote message queues - possible? Pin
jenspa9-Nov-07 1:16
jenspa9-Nov-07 1:16 
QuestionInteresting Project? Pin
daviiie8-Nov-07 23:37
daviiie8-Nov-07 23:37 
AnswerRe: Interesting Project? Pin
Colin Angus Mackay9-Nov-07 0:43
Colin Angus Mackay9-Nov-07 0:43 
GeneralRe: Interesting Project? Pin
daviiie9-Nov-07 1:20
daviiie9-Nov-07 1:20 
Questiongridviewer Pin
merwa8-Nov-07 23:31
merwa8-Nov-07 23:31 
QuestionSimulate mouseclick?? Pin
jafingi8-Nov-07 23:03
jafingi8-Nov-07 23:03 
AnswerRe: Simulate mouseclick?? [modified] Pin
Rajasekharan Vengalil9-Nov-07 0:38
Rajasekharan Vengalil9-Nov-07 0:38 
Here you go!

C#
[Flags]
public enum MouseEvent : uint
{
    MOUSEEVENTF_MOVE = 0x0001,
    MOUSEEVENTF_LEFTDOWN = 0x0002,
    MOUSEEVENTF_LEFTUP = 0x0004,
    MOUSEEVENTF_RIGHTDOWN = 0x0008,
    MOUSEEVENTF_RIGHTUP = 0x0010,
    MOUSEEVENTF_MIDDLEDOWN = 0x0020,
    MOUSEEVENTF_MIDDLEUP = 0x0040,
    MOUSEEVENTF_XDOWN = 0x0080,
    MOUSEEVENTF_XUP = 0x0100,
    MOUSEEVENTF_WHEEL = 0x0800,
    MOUSEEVENTF_VIRTUALDESK = 0x4000,
    MOUSEEVENTF_ABSOLUTE = 0x8000
}

public enum InputType : uint
{
    INPUT_MOUSE = 0,
    INPUT_KEYBOARD = 1,
    INPUT_HARDWARE = 2
}

[StructLayout(LayoutKind.Sequential)]
public struct MOUSEINPUT
{
    private InputType type;
    public UInt32 dx;
    public UInt32 dy;
    public UInt32 mouseData;
    public MouseEvent dwFlags;
    public UInt32 time;
    public IntPtr dwExtraInfo;
}

public static class MouseInput
{
    [DllImport("User32.dll")]
    public static extern UInt32 SendInput(UInt32 nInputs, MOUSEINPUT[] pInputs, int cbSize);

    private static Point Normalize(Point pt)
    {
        return new Point((pt.X * 65535) / Screen.PrimaryScreen.Bounds.Width,
            (pt.Y * 65535) / Screen.PrimaryScreen.Bounds.Height);
    }

    public static void Move(Point pt)
    {
        pt = Normalize(pt);

        MOUSEINPUT[] input = new MOUSEINPUT[1];
        input[0].dx = Convert.ToUInt32(pt.X);
        input[0].dy = Convert.ToUInt32(pt.Y);
        input[0].dwFlags = MouseEvent.MOUSEEVENTF_MOVE | MouseEvent.MOUSEEVENTF_ABSOLUTE;

        SendInput(1, input, Marshal.SizeOf(input[0]));
    }

    public static void Click(Point pt)
    {
        Move(pt);

        pt = Normalize(pt);

        MOUSEINPUT[] input = new MOUSEINPUT[2];
        input[0].dx = Convert.ToUInt32(pt.X);
        input[0].dy = Convert.ToUInt32(pt.Y);
        input[0].dwFlags = MouseEvent.MOUSEEVENTF_LEFTDOWN | MouseEvent.MOUSEEVENTF_ABSOLUTE;

        input[1].dx = Convert.ToUInt32(pt.X);
        input[1].dy = Convert.ToUInt32(pt.Y);
        input[1].dwFlags = MouseEvent.MOUSEEVENTF_LEFTUP | MouseEvent.MOUSEEVENTF_ABSOLUTE;

        SendInput(2, input, Marshal.SizeOf(input[0]));
    }
}
To simulate a click at 100,100 therefore you'd do this:
C#
MouseInput.Click( new Point( 100, 100 ) );
I don't think you can do it without moving the cursor. You could save the current mouse position, click at the point where you want to click and then move right back to the saved position!


GeneralRe: Simulate mouseclick?? Pin
jafingi27-Nov-07 5:13
jafingi27-Nov-07 5:13 
QuestionGeneral Concern Pin
kingletas8-Nov-07 22:50
kingletas8-Nov-07 22:50 
AnswerRe: General Concern Pin
Adeel Chaudhry11-Nov-07 18:59
Adeel Chaudhry11-Nov-07 18:59 
Questionclock( ) function in C# Pin
baerten8-Nov-07 22:31
baerten8-Nov-07 22:31 
AnswerRe: clock( ) function in C# Pin
Giorgi Dalakishvili8-Nov-07 22:46
mentorGiorgi Dalakishvili8-Nov-07 22:46 
GeneralRe: clock( ) function in C# Pin
baerten8-Nov-07 23:28
baerten8-Nov-07 23:28 
GeneralRe: clock( ) function in C# Pin
Giorgi Dalakishvili8-Nov-07 23:30
mentorGiorgi Dalakishvili8-Nov-07 23:30 
QuestionPare C# Code Pin
Ya3sam8-Nov-07 21:59
Ya3sam8-Nov-07 21:59 
AnswerRe: Pare C# Code Pin
Justin Perez9-Nov-07 3:46
Justin Perez9-Nov-07 3:46 
GeneralRe: Pare C# Code Pin
DavidNohejl9-Nov-07 9:09
DavidNohejl9-Nov-07 9:09 
AnswerRe: Pare C# Code Pin
DavidNohejl9-Nov-07 9:14
DavidNohejl9-Nov-07 9:14 
GeneralRe: Pare C# Code Pin
Ya3sam10-Nov-07 22:05
Ya3sam10-Nov-07 22:05 
GeneralRe: Pare C# Code Pin
DavidNohejl11-Nov-07 4:40
DavidNohejl11-Nov-07 4:40 
Questioninserting date to database Pin
troubled one8-Nov-07 21:22
troubled one8-Nov-07 21:22 
AnswerRe: inserting date to database Pin
Giorgi Dalakishvili8-Nov-07 21:32
mentorGiorgi Dalakishvili8-Nov-07 21:32 
AnswerRe: inserting date to database Pin
Guffa8-Nov-07 21:53
Guffa8-Nov-07 21:53 
QuestionString matching Pin
SaphuA8-Nov-07 21:12
SaphuA8-Nov-07 21:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.