2009-10-07 58 views
2

我正在嘗試在C#中創建一個自動化的Clicker程序,以便使某些管理任務更快。總之,我將使用一個程序(Firefox),並且需要一個程序來自動移動鼠標並單擊我所告訴的地方。以編程方式在Firefox中自動執行鼠標移動和點擊操作

目前我有這樣的代碼,儘管我覺得我離實際解決方案還很遙遠。

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's 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(); 
     } 
    } 
} 

我希望我的程序能夠在Firefox上運行,並且一旦它已經加載,立即開始點擊我告訴它的位置。它需要點擊13個30x30像素按鈕,然後停下來,讓我完成任務。

我該怎麼去做這樣的工作?

編輯:我忘了提到,前端是在Flash中。奇怪,我知道。無論哪種方式,這意味着像Selenium這樣的程序不會像軌道頁面移動和點擊鏈接一樣工作。

回答

3

雖然這不能回答你的問題與C#代碼我真的不得不建議你看看AutoIt。這是一種非常簡單的腳本語言,用於創建需要重複定義的任務。我已經成功地將它用於廣泛的任務,從反覆輸入測試Web應用程序的表單數據到與MMO遊戲中的怪物戰鬥。

+0

完美。謝謝! – 2009-10-07 18:26:40

3

是否需要實際自動化鼠標,或只需按下按鈕?您可以使用Selenium輕鬆做到這一點,包括使用爲您生成C#代碼的IDE(FireFox插件)記錄您的操作。

+0

我試過Selenium,但它不適用於Flash應用程序。我忘了提及我需要自動化的部分有一個Flash前端,這是Selenium無法接受的。 – 2009-10-07 16:54:15

+0

像http://code.google.com/p/flash-selenium/這樣的社區版本可以幫助填補這一空白,儘管我不能說我已經使用過它們。 – 2009-10-07 16:56:59

3

要擴展@Chris Marisic的答案,您實際上可以使用AutoIt從C#(或其他語言)使用AutoIt。我沒有試過,但顯然你可以把它編譯成一個DLL,並從你的代碼中調用它,見http://www.autoitscript.com/forum/index.php?showtopic=39262

+0

我不知道的迷人存在 – 2009-10-07 17:31:33