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?

Confirm

Are you sure?

Move Mouse Cursor to Next Monitor and Restore its Previous Position

Description
This script will move the mouse cursor to the next monitor, and restore its previous position for that monitor from the last time the function was run.
Language
C#.net
Minimum Version
Created By
Keith Lammers (BFS)
Contributors
-
Date Created
Feb 27, 2018
Date Last Modified
Feb 27, 2018

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
//   - Trigger target when run by a Trigger 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)
	{
        // Get the monitor ID of the monitor that the mouse cursor is on
        uint currentMonitor = GetCurrentMonitorByMouseCursor();
	
		// Save the current monitor's mouse position to the registry
		BFS.ScriptSettings.WriteValueInt("Monitor_" + currentMonitor.ToString() + "_X", BFS.Input.GetMousePositionX());
		BFS.ScriptSettings.WriteValueInt("Monitor_" + currentMonitor.ToString() + "_Y", BFS.Input.GetMousePositionY());
		
		// Move the mouse cursor to the saved position on the next monitor, if it exists
		BFS.DisplayFusion.RunFunction("Move Mouse Cursor to Next Monitor");
		
        currentMonitor = GetCurrentMonitorByMouseCursor();
        int currentMonitorSavedMouseX = BFS.ScriptSettings.ReadValueInt("Monitor_" + currentMonitor.ToString() + "_X");
        int currentMonitorSavedMouseY = BFS.ScriptSettings.ReadValueInt("Monitor_" + currentMonitor.ToString() + "_Y");
        
        if (currentMonitorSavedMouseX != 0 && currentMonitorSavedMouseY != 0)
            BFS.Input.SetMousePosition(currentMonitorSavedMouseX, currentMonitorSavedMouseY);
	}
	
	public static uint GetCurrentMonitorByMouseCursor()
	{
		// Figure out which monitor the mouse cursor is on
		uint monitorID = BFS.Monitor.GetMonitorIDByRect(BFS.Monitor.GetMonitorBoundsByMouseCursor());
		
		// Return the monitor ID
		return monitorID;
	}
}