2016-05-12 128 views
0

我希望能夠通過C#代碼移動鼠標指針。令人驚訝的是,沒有任何有用的鏈接或以前問過關於相同的問題。移動鼠標指針


我真的想要什麼?只需要一些幫助來編寫一個在while (true) {...}循環中運行的控制檯應用程序並每五分鐘移動一次鼠標。

while (true) { 
    MoveMouseToRandomPosition(); //Move mouse to multiple random positions 
    Thread.Sleep(5 * 60 * 1000); //Go to sleep for the next five minutes 
} 

我真的真的想要什麼?當我在輕鬆的日子在家工作時,能夠運行這個控制檯應用程序,這樣我在Outlook中的狀態就不會變成黃色(這意味着我已經'離開'超過五分鐘了)。


夥計們,請不要把這當成'給我teh codez'問題。提示非常好。我可以自己編寫提示。

+6

我對誠實的印象。 –

+0

你檢查了這個職位? http://stackoverflow.com/questions/8050825/how-to-move-mouse-cursor-using-c – Quakenxt

+0

@Quakenxt:我其實沒有。它在我輸入我的推薦問題時沒有顯示出來。謝謝。 – displayName

回答

1

在WinForms中,您可以使用Cursor對象執行此操作。

private void MoveCursor() 
{ 
    this.Cursor = new Cursor(Cursor.Current.Handle); 
    Cursor.Position = new Point(Cursor.Position.X - 50, Cursor.Position.Y - 50); 
    Cursor.Clip = new Rectangle(this.Location, this.Size); 
} 

Cursor.Position Property