Jump to content

Simular cliques


H4IMRICK_PT
 Share

Recommended Posts

Finalmente consegui encontrar a solução pro meu problema 🙂

Deixo abaixo o código pro caso de alguém ter também o mesmo problema..

Posso não ter criado o código mais profissional do mundo mas funciona 😉


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;
namespace clicks
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        [DllImportAttribute("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        private static extern void mouse_event(UInt32 dwFlags,int dx,int dy,int dwData,IntPtr dwExtraInfo);
        public void click(int xI, int yI)
        {
            int finalX, finalY;
            this.Cursor = new Cursor(Cursor.Current.Handle);
            const UInt32 MOUSEEVENTF_LEFTDOWN = 0x02;
            const UInt32 MOUSEEVENTF_LEFTUP = 0x04;
            const UInt32 MOUSEEVENTF_RIGHTDOWN = 0x08;
            const UInt32 MOUSEEVENTF_RIGHTUP = 0x10;
            const UInt32 MOUSEEVENTF_ABSOLUTE = 0x8000;
            const UInt32 MOUSEEVENTF_MOVE = 0x0001;
            finalX = (xI - Cursor.Position.X);
            finalY = (yI - Cursor.Position.Y);
            Cursor.Position = new Point(Cursor.Position.X + finalX, Cursor.Position.Y + finalY);
            mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_MOVE, 0, 0, 0, new IntPtr());                      
        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            click(1100, 1012);
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Cursor = new Cursor(Cursor.Current.Handle);
            this.Text = (Cursor.Position.X.ToString()+" "+ Cursor.Position.Y.ToString());
        }
    }
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.