Difference between revisions of "C-Sharp - Input Simulator"
Jump to navigation
Jump to search
PeterHarding (talk | contribs) |
PeterHarding (talk | contribs) |
||
Line 10: | Line 10: | ||
<pre> | <pre> | ||
public partial class | public partial class MainForm : Form | ||
{ | { | ||
[DllImport("user32.dll")] | [DllImport("user32.dll")] | ||
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, | private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); | ||
[DllImport("user32.dll", EntryPoint = "WindowFromPoint", | [DllImport("user32.dll", EntryPoint = "WindowFromPoint", CharSet = CharSet.Auto, ExactSpelling = true)] | ||
public static extern IntPtr WindowFromPoint(Point point); | public static extern IntPtr WindowFromPoint(Point point); | ||
private const int BM_CLICK = 0x00F5; | private const int BM_CLICK = 0x00F5; | ||
public | public MainForm() | ||
{ | { | ||
InitializeComponent(); | InitializeComponent(); | ||
Line 30: | Line 28: | ||
{ | { | ||
// Specify the point you want to click | // Specify the point you want to click | ||
var screenPoint = this.PointToScreen(new Point(button2.Left, | |||
var screenPoint = this.PointToScreen(new Point(button2.Left, button2.Top)); | |||
// Get a handle | // Get a handle | ||
var handle = WindowFromPoint(screenPoint); | var handle = WindowFromPoint(screenPoint); | ||
// Send the click message | // Send the click message | ||
if (handle != IntPtr.Zero) | if (handle != IntPtr.Zero) | ||
{ | { | ||
Line 45: | Line 47: | ||
MessageBox.Show("Hi", "There"); | MessageBox.Show("Hi", "There"); | ||
} | } | ||
} | } | ||
</pre> | </pre> |
Revision as of 22:22, 28 May 2015
Simulators
Other Links
Eample 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"); } }