Automatic mouse movement and clicks in Firefox programmatically

I am trying to create an automatic clicker program in C # to do some administrative tasks faster. In short, I will be using one program (Firefox) and you will need a program to automatically move the mouse and click wherever I say.

At the moment I have this code, although I think I am quite far from the actual solution.

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.Drawing;

namespace Clicker
{
    public partial class Form1 : Form
    {

        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);

        private const int MOUSEEVENTF_LEFTDOWN = 0x02;
        private const int MOUSEEVENTF_LEFTUP = 0x04;
        private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
        private const int MOUSEEVENTF_RIGHTUP = 0x10;

        public void DoMouseClick()
        {
            //Call the imported function with the cursor current position
            Cursor.Position = new Point((int)10, (int)10);

            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, Cursor.Position.X, Cursor.Position.Y, 0, 0);
        }

        public Form1()
        {
            //InitializeComponent();
        }
    }
}

      

I want my program to run on top of Firefox and as soon as it has loaded, to immediately start clicking on the positions I'm talking about. It will have to click thirteen 30x30px buttons and then stop, leaving me to complete the task.

How can I solve this problem?

EDIT: I forgot to mention that the front-end is in Flash. Strange, I know. In any case, this means that programs like Selenium will not work as path movements and link clicks.

+2


source to share


4 answers


Until this answers your question with C # code, I would really need to recommend that you look into AutoIt . It is a very simple scripting language for creating specific tasks that need to be repeated. I have used it successfully for a wide variety of tasks from multiple form data entry to testing monster fighting web applications in an MMO game.



+3


source


Do I need to actually automate the mouse or just click buttons? You can easily do this with Selenium , including recording your actions with an IDE (FireFox addon), which outputs the C # code for you.



+3


source


To expand on @Chris Marisic's answer, you can use AutoIt from C # (or other languages) with AutoItX. I haven't tried this, but apparently you can compile it into a DLL and call it from your code, see http://www.autoitscript.com/forum/index.php?showtopic=39262

+3


source


Here's a simple library that's pretty nifty:

http://www.codeproject.com/KB/system/globalmousekeyboardlib.aspx

+1


source







All Articles