Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Move Mouse Cursor in a Circle

Description
This function moves the mouse cursor in a circle, demonstrating how to move the mouse with DisplayFusion.
Language
C#.net
Minimum Version
Created By
Thomas Malloch (BFS)
Contributors
-
Date Created
Sep 29, 2014
Date Last Modified
Oct 3, 2014

Scripted Function (Macro) Code

using System;
using System.Drawing;

// The 'windowHandle' parameter will contain the window handle for the:
//   - Active window when run by hotkey
//   - Window Location target when run by a Window Location rule
//   - TitleBar Button owner when run by a TitleBar Button
//   - Jump List owner when run from a Taskbar Jump List
//   - Currently focused window if none of these match
public static class DisplayFusionFunction
{
	public static void Run(IntPtr windowHandle)
	{
		//the radius of the circle in pixels
		double radius = 100.0d;
		
		//get the center of the circle we want to draw
		int startX = BFS.Input.GetMousePositionX() - (int)radius;
		int startY = BFS.Input.GetMousePositionY();
		
		//iterate from 0 to 2PI (360 degrees)
		for (double i = 0.0d; i < Math.PI * 2.0d; i+=0.1d)
		{
			//convert polar coordinates to cartesian
			int x = startX +(int)(radius * Math.Cos(i));
			int y = startY +(int)(radius * Math.Sin(i));
			
			//set the new mouse position
			BFS.Input.SetMousePosition(x, y);
			
			//sleep for a bit
			BFS.General.Sleep(10);
		}
	}
}