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?
Save up to 50% on our desktop apps during our Year End Sale!Save up to 50% on our desktop apps during our Year End Sale, including DisplayFusion, ClipboardFusion, FileSeek, LogFusion, TrayStatus, and VoiceBot!Save up to 50% on our desktop apps during our Year End Sale!

FluffyBunnyFeet's profile on WallpaperFusion.com
Is there a quick way to get the current mouse position?
I have a command that moves the mouse and does some clicks, then returns the mouse to the position prio to any of the moves/clicks. The problem is that the script macro for getting and storing the mouse position is extremely slow (3-5 seconds for just getting/storing the mouse position, and then another 3-5 seconds to have the follow-up script return the mouse to its previous coordinates). Add to it that it pretty much opens another window.

1. Macro Script to get/store the mouse position
=============================================

Code

using System;
using System.Drawing;

public static class VoiceBotScript
{
    public static void Run(IntPtr windowHandle)
    {
    int mouseX = BFS.Input.GetMousePositionX();
    int mouseY = BFS.Input.GetMousePositionY();
    BFS.ScriptSettings.WriteValueInt("MouseX", mouseX);
    BFS.ScriptSettings.WriteValueInt("MouseY", mouseY);
    }
}

=============================================

2. Multiple "move/click here" commands.
3. Macro Script to restore the mouse position to previously saved coordinates:
=============================================

Code

using System;
using System.Drawing;

public static class VoiceBotScript
{
    public static void Run(IntPtr windowHandle)
    {
    int mouseX = BFS.ScriptSettings.ReadValueInt("MouseX");
    int mouseY = BFS.ScriptSettings.ReadValueInt("MouseY");
    BFS.Input.SetMousePosition(mouseX , mouseY); //Moves the mouse cursor to the earlier stored values.
    }
}

=============================================

Unfortunately, using these macro scripts are just too damn slow (it works, but takes up to 10 seconds just for 3 steps (get position, move mouse, and move mouse back to previous position. Other voice command software has a simpler (and much quicker) way to grab the mouse coordinates, and then recall those variables/values later-on. Is there an easier way to do this in Voicebot?

Please advise.

Thanks,

Van
Aug 28, 2018 (modified Aug 28, 2018)  • #1
PabloMartinez's profile on WallpaperFusion.com
What causes the use of 3 scripts? Of course, their launch and works takes a long time. Everything is solved much easier.
For example this test script with 50 clicks, is executed in ~6 seconds. And 99% of this time is spent on clicks. Without clicks, but with 10ms delay it's performed for ~550ms.

Code

using System;
using System.Drawing;
using System.Linq;
using System.Diagnostics;

public static class VoiceBotScript
{
    public static void Run(IntPtr windowHandle)
    {
        // Calculate execution time
        var watch = Stopwatch.StartNew();
        
        // Save current position
        var pos = new int[] {BFS.Input.GetMousePositionX(), BFS.Input.GetMousePositionY()};
        
        // Call method with mouse actions
        MouseActions();
        
        // Restore saved position
        BFS.Input.SetMousePosition(pos[0], pos[1]);
        
        watch.Stop();
        BFS.Dialog.ShowMessageInfo("Total time elapsed: " + watch.Elapsed);
    }
    
    public static void MouseActions()
    {
        // Here your can make all mouse actions.
        
        // For example, 50 clicks with the initial coordinates of X=300, Y=500 and X offset by +10 pixels to 500.
        var posList = Enumerable.Range(300, 500).Where(x => x % 10 == 0).ToList();
        foreach (var pos in posList)
        {
            BFS.Input.SetMousePosition(pos, 500);
            //BFS.General.ThreadWait(10);
            BFS.Input.LeftClickMouse();
        }
    }
}
Aug 29, 2018 (modified Aug 29, 2018)  • #2
PabloMartinez's profile on WallpaperFusion.com
Well, just in case, a clean script.

Code

using System;
using System.Drawing;

public static class VoiceBotScript
{
    public static void Run(IntPtr windowHandle)
    {
        // Save current position
        var posX = BFS.Input.GetMousePositionX();
        var posY = BFS.Input.GetMousePositionY();
        
        // Call method with mouse actions
        MouseActions();
        
        // Restore saved position
        BFS.Input.SetMousePosition(posX, posY);
    }
    public static void MouseActions()
    {
        // Here your can make all mouse actions.
    }
}
Aug 29, 2018  • #3
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)