Closed sw3103 closed 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)
thank you Steve!
e.g.
Originally posted by @W-illi4m in https://github.com/sw3103/movemouse/issues/71#issuecomment-2390807360