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

C#

 
GeneralRe: Display a presentation on TV Pin
SquallBlade1-Feb-05 21:53
SquallBlade1-Feb-05 21:53 
GeneralRe: Display a presentation on TV Pin
Dave Kreskowiak2-Feb-05 1:51
mveDave Kreskowiak2-Feb-05 1:51 
GeneralRe: Display a presentation on TV Pin
SquallBlade2-Feb-05 3:52
SquallBlade2-Feb-05 3:52 
GeneralRe: Display a presentation on TV Pin
Heath Stewart2-Feb-05 6:34
protectorHeath Stewart2-Feb-05 6:34 
GeneralRe: Display a presentation on TV Pin
Christian Graus2-Feb-05 9:03
protectorChristian Graus2-Feb-05 9:03 
Generalsynthesize mouse click Pin
Some Idiot1-Feb-05 11:05
Some Idiot1-Feb-05 11:05 
GeneralRe: synthesize mouse click Pin
Christian Graus1-Feb-05 11:21
protectorChristian Graus1-Feb-05 11:21 
GeneralRe: synthesize mouse click Pin
Heath Stewart1-Feb-05 15:33
protectorHeath Stewart1-Feb-05 15:33 
That won't actually click the object, however, even if it were within your application. The Click event fires in response to a click.

To simulate a click, you need to P/Invoke SendInput (this is the easiest) and send the screen coordinates for the click:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
 
class Click
{
  static void Main(string[] args)
  {
    if (args.Length != 2)
      Environment.Exit(1);
 
    Point p = new Point();
    p.X = int.Parse(args[0]);
    p.Y = int.Parse(args[1]);
 
    ClickAt(p);
  }
 
  [DllImport("user32.dll", SetLastError=true)]
  [return: MarshalAs(UnmanagedType.U4)]
  static extern int SendInput(
    [MarshalAs(UnmanagedType.U4)] int nInputs,
    INPUT[] pInputs,
    int cbSize);
 
  [StructLayout(LayoutKind.Explicit)]
  struct INPUT
  {
    [FieldOffset(0), MarshalAs(UnmanagedType.U4)] public int type;
    [FieldOffset(4)] public MOUSEINPUT mi;
    // [FieldOffset(4)] public KEYBDINPUT ki;
    // [FieldOffset(4)] public HARDWAREINPUT hi;
  }
 
  const int INPUT_MOUSE = 0;
  const int INPUT_KEYBOARD = 1;
  const int INPUT_HARDWARE = 2;
 
  [StructLayout(LayoutKind.Sequential)]
  struct MOUSEINPUT
  {
    public int dx;
    public int dy;
    [MarshalAs(UnmanagedType.U4)] public int mouseData;
    [MarshalAs(UnmanagedType.U4)] public int dwFlags;
    [MarshalAs(UnmanagedType.U4)] public int time;
    [MarshalAs(UnmanagedType.SysUInt)] public IntPtr dwExtraInfo;
  }
 
  const int MOUSEEVENTF_ABSOLUTE = 0x8000;
 
  public static void ClickAt(Point p)
  {
    MOUSEINPUT mi = new MOUSEINPUT();
    mi.dx = p.X;
    mi.dy = p.Y;
    mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
 
    INPUT[] inputs = new INPUT[1];
    inputs[0].type = INPUT_MOUSE;
    inputs[0].mi = mi;
 
    int ret = SendInput(1, inputs, Marshal.SizeOf(typeof(INPUT)));
    if (ret != 0)
      throw new Win32Exception();
  }
}
This is just a sample I threw together quick, but be sure to read about the APIs and structs used in the example.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralRe: synthesize mouse click Pin
Some Idiot2-Feb-05 1:12
Some Idiot2-Feb-05 1:12 
GeneralRe: synthesize mouse click Pin
Heath Stewart2-Feb-05 6:17
protectorHeath Stewart2-Feb-05 6:17 
GeneralRe: synthesize mouse click Pin
Heath Stewart1-Feb-05 15:34
protectorHeath Stewart1-Feb-05 15:34 
Generalmultiple tables binding to a grid Pin
cuah1-Feb-05 10:46
cuah1-Feb-05 10:46 
GeneralRe: multiple tables binding to a grid Pin
Heath Stewart1-Feb-05 15:16
protectorHeath Stewart1-Feb-05 15:16 
GeneralHyperlink Value Pin
myousufq1-Feb-05 10:12
myousufq1-Feb-05 10:12 
GeneralRe: Hyperlink Value Pin
Heath Stewart1-Feb-05 10:20
protectorHeath Stewart1-Feb-05 10:20 
GeneralRe: Hyperlink Value Pin
myousufq1-Feb-05 10:37
myousufq1-Feb-05 10:37 
GeneralRe: Hyperlink Value Pin
Heath Stewart1-Feb-05 10:52
protectorHeath Stewart1-Feb-05 10:52 
GeneralRe: Hyperlink Value Pin
Heath Stewart1-Feb-05 10:56
protectorHeath Stewart1-Feb-05 10:56 
GeneralRe: Hyperlink Value Pin
myousufq2-Feb-05 3:39
myousufq2-Feb-05 3:39 
GeneralRe: Hyperlink Value Pin
Heath Stewart2-Feb-05 6:30
protectorHeath Stewart2-Feb-05 6:30 
GeneralRe: Hyperlink Value Pin
myousufq2-Feb-05 7:22
myousufq2-Feb-05 7:22 
GeneralRe: Hyperlink Value Pin
Heath Stewart2-Feb-05 7:29
protectorHeath Stewart2-Feb-05 7:29 
GeneralRe: Hyperlink Value Pin
myousufq3-Feb-05 1:56
myousufq3-Feb-05 1:56 
GeneralDumb question about Mono C# Pin
FocusedWolf1-Feb-05 10:06
FocusedWolf1-Feb-05 10:06 
GeneralRe: Dumb question about Mono C# Pin
Judah Gabriel Himango1-Feb-05 10:13
sponsorJudah Gabriel Himango1-Feb-05 10:13 

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.