バッチファイルとパワーシェルでマウスを操作する powershell
バッチファイル
@powershell/c '#'+(Get-Content \"%~f0\"-raw)^|Invoke-Expression &timeout /t 50&goto:eof
# const definition
$MOUSEEVENTF_MOVED = 0x0001 ;
$MOUSEEVENTF_LEFTDOWN = 0x0002 ;
$MOUSEEVENTF_LEFTUP = 0x0004 ;
$MOUSEEVENTF_RIGHTDOWN = 0x0008 ;
$MOUSEEVENTF_RIGHTUP = 0x0010 ;
$MOUSEEVENTF_MIDDLEDOWN = 0x0020 ;
$MOUSEEVENTF_MIDDLEUP = 0x0040 ;
$MOUSEEVENTF_WHEEL = 0x0080 ;
$MOUSEEVENTF_XDOWN = 0x0100 ;
$MOUSEEVENTF_XUP = 0x0200 ;
$MOUSEEVENTF_ABSOLUTE = 0x8000 ;
# Variable definition
$x = 400
$y = 400
# .NET Framework declaration
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName System.Windows.Forms
# Windows API declaration
$Signature = @'
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern void mouse_event(long dwFlags , long dx, long dy, long dwData, long dwExtraInfo);
'@
$MouseClick = Add-Type -memberDefinition $signature -name "Win32MouseEventNew" -namespace Win32Functions -passThru
Start-Sleep -s 11
# Move mouse cursor
$POSITION = [System.Windows.Forms.Cursor]::Position
$POSITION.x = $x
$POSITION.y = $y
[System.Windows.Forms.Cursor]::Position = $POSITION
#[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x, $y)
Start-Sleep -s 11
# Left click
$MouseClick::mouse_event(0x0002, 0, 0, 0, 0); #Left mouse button DOWN
$MouseClick::mouse_event(0x0004, 0, 0, 0, 0); #Left mouse button UP
Start-Sleep -s 11
#Double left click
$MouseClick::mouse_event(0x0002, 0, 0, 0, 0); #Left mouse button down
$MouseClick::mouse_event(0x0004, 0, 0, 0, 0); #Left mouse button UP
$MouseClick::mouse_event(0x0002, 0, 0, 0, 0); #Left mouse button DOWN
$MouseClick::mouse_event(0x0004, 0, 0, 0, 0); #Left mouse button UP
Start-Sleep -s 11
# Right click
$MouseClick::mouse_event(0x0008, 0, 0, 0, 0); # Right mouse button down
$MouseClick::mouse_event(0x0010, 0, 0, 0, 0); # Right mouse button down Button UP
Start-Sleep -s 11
# MIDDLE click
$MouseClick::mouse_event(0x0020 , 0, 0, 0, 0); # MIDDLE mouse button down
$MouseClick::mouse_event(0x0040 , 0, 0, 0, 0); # MIDDLE mouse button down Button UP
mouse_event function (winuser.h) – Win32 apps | Microsoft Learn
ディスカッション
コメント一覧
まだ、コメントがありません