Difference between revisions of "C-Sharp - Input Simulator"

From PeformIQ Upgrade
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Simulators=


* http://inputsimulator.codeplex.com/
=Other Links=
* http://stackoverflow.com/questions/7315196/performing-a-mouse-click-without-moving-cursor
=Example Code=
<pre>
public partial class MainForm : Form
{
    [DllImport("user32.dll")]
    private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
    [DllImport("user32.dll", EntryPoint = "WindowFromPoint", CharSet = CharSet.Auto, ExactSpelling = true)]
    public static extern IntPtr WindowFromPoint(Point point);
    private const int BM_CLICK = 0x00F5;
    public MainForm()
    {
        InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e)
    {
        // Specify the point you want to click
        var screenPoint = this.PointToScreen(new Point(button2.Left, button2.Top));
        // Get a handle
        var handle = WindowFromPoint(screenPoint);
        // Send the click message
        if (handle != IntPtr.Zero)
        {
            SendMessage( handle, BM_CLICK, IntPtr.Zero, IntPtr.Zero);
        }
    }
    private void button2_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Hi", "There");
    }


* http://inputsimulator.codeplex.com/
}
</pre>


[[Category:CSharp]]
[[Category:CSharp]]
[[Category:Simulators]]
[[Category:Simulators]]

Latest revision as of 21:23, 28 May 2015

Simulators

Other Links

Example Code

public partial class MainForm : Form
{
    [DllImport("user32.dll")]
    private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

    [DllImport("user32.dll", EntryPoint = "WindowFromPoint", CharSet = CharSet.Auto, ExactSpelling = true)]
    public static extern IntPtr WindowFromPoint(Point point);

    private const int BM_CLICK = 0x00F5;

    public MainForm()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        // Specify the point you want to click

        var screenPoint = this.PointToScreen(new Point(button2.Left, button2.Top));

        // Get a handle

        var handle = WindowFromPoint(screenPoint);

        // Send the click message

        if (handle != IntPtr.Zero)
        {
            SendMessage( handle, BM_CLICK, IntPtr.Zero, IntPtr.Zero);
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Hi", "There");
    }

}