티스토리 뷰

프로그래밍/C#

C# 마우스 오토클릭 매크로 만들기

뽀로로친구에디 2024. 10. 22. 09:38

 

안녕하세요. 마우스오토클릭을 만들어봤습니다. 

좌표를 설정해서 그 부분만 오토클릭하는 것입니다. 

클릭수를 지정할수 있습니다. 

 

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Net.Mime.MediaTypeNames;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace autoclick
{
    
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        
        private static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);

        public Form1()
        {
            InitializeComponent();
            textBoxX.Text = (Properties.Settings.Default.pos_x).ToString();
            textBoxY.Text = (Properties.Settings.Default.pos_y).ToString();
            hScrollBar1.Value = Properties.Settings.Default.click_count;
            label_click.Text = "클릭수: " + hScrollBar1.Value.ToString();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            mouse_event(0x02, 0, 0, 0, 0);
            System.Threading.Thread.Sleep(10);
            mouse_event(0x04, 0, 0, 0, 0);

            Point p = Cursor.Position;

            if(p.X != Convert.ToInt32(textBoxX.Text))
                StopAutoclick();

        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            StartAutoclick();
        }

        private void buttonStop_Click(object sender, EventArgs e)
        {
            StopAutoclick();
        }

        private void StartAutoclick()
        {
           int x, y;
            x = Convert.ToInt32(textBoxX.Text);
            y = Convert.ToInt32(textBoxY.Text);

            Properties.Settings.Default.pos_x = x;
            Properties.Settings.Default.pos_y = y;
            Properties.Settings.Default.click_count = hScrollBar1.Value;
            Properties.Settings.Default.Save();
        
            Cursor.Position = new Point(x, y);// 마우스 좌표 설정
            timer1.Interval = (int)(1000.0 / hScrollBar1.Value);

            timer1.Start();
            buttonStart.Enabled = false;
            buttonStop.Enabled = true;

        }

        private void StopAutoclick()
        {
            timer1.Stop();

            buttonStart.Enabled = true;
            buttonStop.Enabled = false;

        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            Point p = Cursor.Position;
            label_mouse.Text = "마우스 좌표 X 위치: " + p.X + " Y 위치: " + p.Y;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer2.Start();

            
        }

    
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            timer1.Stop();
            timer2.Stop();
            
        }

        private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            label_click.Text = "클릭수: " + hScrollBar1.Value.ToString();
            
        }

   
    }
}
댓글
최근에 달린 댓글
글 보관함
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Total
Today
Yesterday
    뽀로로친구에디
    최근에 올라온 글