C#滑鼠點擊器-沒有測試-轉自http://hi.baidu.com/syq_ghost/item/2cc253eb538b72e7fb42ba44

來源:互聯網
上載者:User
C#滑鼠點擊器

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

using System.Threading;

using System.Text.RegularExpressions;

 

namespace WindowsFormsApplication5

{

    public partial class Form1 : Form

    {

        [DllImport("user32")]

        private static extern int mouse_event(int dwFlags,int dx,int dy,int cButtons,int dwExtraInfo);

        const int MOUSEEVENT_LEFTDOWN = 0x0002;

        const int MOUSEEVENT_LEFTUP = 0x0004;        

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            string pattern=@"^\d+(\.\d)?$";

            timer1.Enabled = true;

            if (Regex.IsMatch(textBox2.Text, pattern))

            {

                timer1.Interval = int.Parse(this.textBox2.Text);

                timer1.Start();

            }

            else

            {

                timer1.Stop();

                timer1.Enabled = false;

                MessageBox.Show("請輸入整數!","系統提示:",MessageBoxButtons.OK,MessageBoxIcon.Error);                

            }                       

            

        }

 

        private void Mouse_Click()

        {                                               

            mouse_event(MOUSEEVENT_LEFTDOWN, 0, 0, 0, 0);

            mouse_event(MOUSEEVENT_LEFTUP, 0, 0, 0, 0);

            textBox2.Focus();

        }       

 

        private void timer1_Tick(object sender, EventArgs e)

        {            

            Mouse_Click();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            textBox2.Focus();

        }

 

        private void textBox2_Click(object sender, EventArgs e)

        {

            this.textBox2.SelectAll();

        }

 

        private void textBox2_KeyDown(object sender, KeyEventArgs e)

        {

            string pattern = @"^\d+(\.\d)?$";

            if (e.KeyCode == Keys.PageUp)

            {

                if (Regex.IsMatch(textBox2.Text, pattern))

                {

                    timer1.Enabled = true;

                    timer1.Interval = int.Parse(this.textBox2.Text);

                    timer1.Start();

                }

                else

                {

                    timer1.Stop();

                    timer1.Enabled = false;

                    MessageBox.Show("錯誤:請輸入整數!", "系統提示:", MessageBoxButtons.OK, MessageBoxIcon.Error);

                }

            }

            else if (e.KeyCode == Keys.PageDown)

            {

                timer1.Enabled = true;

                timer1.Stop();

            }

        }

    }

}

 

C#同樣能實現滑鼠點擊功能,我試著寫了一個,玩遊戲的朋友們應該用的著,希望對你們有用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.