Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

User Image
mark310
1 discussion post
I'm using a keyboard shortcut to move the active window to the next monitor.
I was wondering if it's possible to also move the mouse cursor to the active window new location ?

Thanks
Jun 25, 2017  • #1
PabloMartinez's profile on WallpaperFusion.com
  • In "Functions" select "Add scripted"
  • Past this code to editor
  • Set name of script
  • Set "Key Combination" to run
  • Use it :laugh:

Code

using System;
using System.Drawing;

public static class DisplayFusionFunction
{
    public static void Run(IntPtr windowHandle)
    {
        // Get focused window handle
        var wHandle = BFS.Window.GetFocusedWindow();
        
        // Move window to next monitor
        BFS.Window.MoveToNextMonitor(wHandle);
        
        // Get window bounds
        var wBounds = BFS.Window.GetBounds(wHandle);
        
        // Move mouse to center of window
        BFS.Input.SetMousePosition(wBounds.Width/2 + wBounds.X, wBounds.Height/2 + wBounds.Y);
    }
}
Jun 25, 2017  • #2
User Image
mANgLEr
10 discussion posts
How could I go about moving the mouse automatically if clicking a titlebar button to move the window to a different monitor? I cannot see how to attach this C# script to the existing button.
Jun 26, 2017  • #3
PabloMartinez's profile on WallpaperFusion.com
When you select a script from the function list, click "Toggle TitleBar Button", select the appropriate icon and apply. Now button will appear in the title bar and will be tied to the script. If you want to move mouse to the title rather than the center of the window, change

Code

BFS.Input.SetMousePosition(wBounds.Width/2 + wBounds.X, wBounds.Height/2 + wBounds.Y);
to

Code

BFS.Input.SetMousePosition(wBounds.Width/2 + wBounds.X, wBounds.Y + 15);
.
Jun 26, 2017 (modified Jun 26, 2017)  • #4
User Image
mANgLEr
10 discussion posts
I should probably have created a new thread for this. Thanks for the tip attaching the script to a button. The script is close to what I'm after, except I want to choose the monitor to move the window to. Looking at a few of the downloadable scripts I've updated the script to:

Code

var wHandle = BFS.Window.GetFocusedWindow();
BFS.DisplayFusion.RunFunction("Move Window to Different Monitor (shows monitor selector)");
var wBounds = BFS.Window.GetBounds(wHandle);
BFS.Input.SetMousePosition(wBounds.X, wBounds.Y);


However, this does not move the mouse cursor at all once the window has moved to the monitor I select in the popup. The mouse remains at the position the monitor selector was at when I clicked it.
Jun 26, 2017 (modified Jun 26, 2017)  • #5
PabloMartinez's profile on WallpaperFusion.com
X and Y are the coordinates of the beginning of the window. i.e. the edge of the top and left side.

Now with the monitor selector.

Code

using System;
using System.Drawing;

public static class DisplayFusionFunction
{
    public static void Run(IntPtr windowHandle)
    {
        var monID = BFS.Monitor.ShowMonitorSelector();
        BFS.Window.MoveToMonitor(monID, windowHandle);
        var wBounds = BFS.Window.GetBounds(windowHandle);
        BFS.Input.SetMousePosition(wBounds.Width / 2 + wBounds.X, wBounds.Y + 15);
    }
}
Jun 26, 2017 (modified Jun 26, 2017)  • #6
User Image
mANgLEr
10 discussion posts
Thanks, that works once I re-ordered the lines to select the monitor first before moving the mouse.
Jun 26, 2017  • #7
PabloMartinez's profile on WallpaperFusion.com
Of course it is. First, move to monitor and then define the bounds.
Oh. Where is my attentiveness? :'(
Jun 26, 2017  • #8
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)