using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Media;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MouseMoverTest
{
public partial class Form1 : Form
{
Timer tmr = new Timer();
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
//Mouse actions
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
static int serviceWaitTime = Convert.ToInt32(ConfigurationManager.AppSettings["TimeToClick"]);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
tmr.Tick += new System.EventHandler(tmr_Tick);
tmr.Interval = serviceWaitTime;
tmr.Enabled = true;
}
private void tmr_Tick(object sender, EventArgs e)
{
tmr.Enabled = false;
DoMouseClick();
tmr.Enabled = true;
}
public void DoMouseClick()
{
//Call the imported function with the cursor's current position
uint X = (uint)Cursor.Position.X;
uint Y = (uint)Cursor.Position.Y;
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
SoundPlayer simpleSound = new SoundPlayer(@"c:\Windows\Media\chimes.wav");
simpleSound.Play();
}
}
}
No comments:
Post a Comment