Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[C#] Simulating a left-click.

Joined
Dec 1, 2007
Messages
2,795
Reaction score
480
Trying to simulate a left click after in the current cursor location but so far no luck, I'm hoping you can help me out abit here.

Basically what I'm trying to do is, when the scroll-wheel is clicked it will automatically switch to weapon 6 [F6], then 'fire' the weapon once [left-click], and then switch to weapon 3 [F3].

Basically everything is finished except simulating the mouse click and make the form run as a background process.
PHP:
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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        private static extern void mouse_event(
        UInt32 dwFlags, // motion and click options
        UInt32 dx, // horizontal position or change
        UInt32 dy, // vertical position or change
        UInt32 dwData, // wheel movement
        IntPtr dwExtraInfo // application-defined information
        );

        public static void PerformSingleLeftMouseClick(Point cursorLocation)
        {
            const UInt32 MOUSEEVENTF_LEFTDOWN = 0x02; /* right button down */
            const UInt32 MOUSEEVENTF_LEFTUP = 0x04; /* right button up */

            UInt32 x = Convert.ToUInt32(cursorLocation.X);
            UInt32 y = Convert.ToUInt32(cursorLocation.Y);

            mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, new IntPtr());
            mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, new IntPtr());
        }


        public Form1()
        {
            InitializeComponent();
            this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form_MouseDown); 
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Form_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            switch (e.Button)
            {
                case MouseButtons.Left:
                    // future stuff MessageBox.Show(this, "Left Button Click");
                    break;
                case MouseButtons.Right:
                    // future stuff MessageBox.Show(this, "Right Button Click");
                    break;
                case MouseButtons.Middle:
                    // future stuff MessageBox.Show("Middle Button Click");
                    SendKeys.Send("{F6}");
                        // need to make a left click here
                    SendKeys.Send("{F3}");
                    break;
                default:
                    break;
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
           
        } 
    }
}
 
Custom Title Activated
Loyal Member
Joined
May 18, 2006
Messages
2,065
Reaction score
14
user32.dll doesn't have a mouse_click function. The method name must be the same as the one in the DLL, I believe.
 
Joined
Dec 1, 2007
Messages
2,795
Reaction score
480
Thanks, ended up getting it to work but I've run into another brick wall.
How would I run it in the background and still be able to 'activate' the middle click, currently it just focus's on the window that I'm clicking, it only works when I click on the form.
 
Ginger by design.
Loyal Member
Joined
Feb 15, 2007
Messages
2,340
Reaction score
653
Thanks, ended up getting it to work but I've run into another brick wall.
How would I run it in the background and still be able to 'activate' the middle click, currently it just focus's on the window that I'm clicking, it only works when I click on the form.

It depends on how the game gathers input like mouse clicks.
 
Joined
Dec 1, 2007
Messages
2,795
Reaction score
480
Not sure but I've heard others use third party programs similar, I'm sure if people can use aimbots and stuff like that then surely I could have something to pull out defibrillator pack lol
 
Skilled Illusionist
Joined
Apr 22, 2009
Messages
301
Reaction score
19
I don't understand, you want your program to run in background and click on the active window? I thought mouse_event() did it that way (at least when i used it).
 
Joined
Dec 1, 2007
Messages
2,795
Reaction score
480
I don't understand, you want your program to run in background and click on the active window? I thought mouse_event() did it that way (at least when i used it).
Well I'll give an example to explain it better.

I change the SendKeys from F6 to F1 (should launch the help file for WMP), I now have my application running, I launch Windows Media Player and make it fullscreen I scroll-wheel click but it doesn't launch the help file.
 
Back
Top