sw3103 / movemouse

Move Mouse is a simple piece of software that is designed to simulate user activity.
http://www.movemouse.co.uk/
GNU General Public License v3.0
576 stars 108 forks source link

is it possible to add a feature to type text? #74

Closed sw3103 closed 1 month ago

sw3103 commented 1 month ago
          is it possible to add a feature to type text?

e.g.

  1. position cursor
  2. type text "my text"
  3. position cusror
  4. click

Originally posted by @W-illi4m in https://github.com/sw3103/movemouse/issues/71#issuecomment-2390807360

sw3103 commented 1 month ago

Taken from examples in the PowerShell Snippets section of the Wiki (excuse formatting).

Save the code below to a .ps1 file launch from Move Mouse or anything else.

Add-Type -TypeDefinition @" using System; using System.Threading; using System.Runtime.InteropServices;

namespace NativeMethods { public static class Mouse { [DllImport("user32.dll")] public static extern void mouse_event(MouseEventFlags dwFlags, int dx, int dy, int dwData, UIntPtr dwExtraInfo);

    [DllImport("User32.dll")]
    public static extern bool SetCursorPos(
        int X,
        int Y);

    [Flags]
    public enum MouseEventFlags
    {
        LEFTDOWN = 0x00000002,
        LEFTUP = 0x00000004,
        MIDDLEDOWN = 0x00000020,
        MIDDLEUP = 0x00000040,
        MOVE = 0x00000001,
        ABSOLUTE = 0x00008000,
        RIGHTDOWN = 0x00000008,
        RIGHTUP = 0x00000010,
        WHEEL = 0x0800
    }

    public static void MouseDown()
    {
        mouse_event(MouseEventFlags.LEFTDOWN, 0, 0, 0, UIntPtr.Zero);
    }

    public static void MouseUp()
    {
        mouse_event(MouseEventFlags.LEFTUP, 0, 0, 0, UIntPtr.Zero);
    }
}

} "@

NativeMethods.Mouse::SetCursorPos(200, 200) $WshShell = New-Object -ComObject WScript.Shell $WshShell.SendKeys("my text") NativeMethods.Mouse::SetCursorPos(200, 400)

W-illi4m commented 1 month ago

thank you Steve!