バッチファイルとパワーシェルでマウスとキーボードを操作する powershell

バッチファイル

コンソールにやっている内容を表示しビープ音を鳴らします

wheelうまく動きません

@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  


# Move mouse cursor  
$POSITION = [System.Windows.Forms.Cursor]::Position
Write-Host $POSITION.x  ' ' $POSITION.y

$POSITION.x = $x
$POSITION.y = $y
Write-Host $POSITION.x  ' ' $POSITION.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 
Write-Host  '# Left click  '
[Console]::Beep(440, 100)
$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

# Enter 
Write-Host  '# Enter '
[Console]::Beep(740, 100)
[Windows.Forms.SendKeys]::SendWait('{Enter}')

Start-Sleep -s 11

# Double left click
Write-Host  '# Double left click '
[Console]::Beep(494, 10)
[Console]::Beep(494, 10)
$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 
Write-Host  '# Right click  '
[Console]::Beep(554, 100)
$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 
Write-Host  '# MIDDLE click  '
[Console]::Beep(587, 100)
$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

Start-Sleep -s 11

# Drag and Drop
Write-Host  '# Drag and Drop '
[Console]::Beep(659, 500)
$MouseClick::mouse_event(0x0002, 0, 0, 0, 0); #Left mouse button down
Start-Sleep -s 11
Write-Host  '# Left mouse button UP '
[Console]::Beep(659, 100)
$MouseClick::mouse_event(0x0004, 0, 0, 0, 0); #Left mouse button UP
Start-Sleep -s 11


# wheel
Write-Host  '# wheel '
[Console]::Beep(740, 500)
$MouseClick::mouse_event(0x0800, 0, 0, -100, 0); # mouse wheel
[Console]::Beep(831, 500)
$MouseClick::mouse_event(0x0800, 0, 0, 100, 0); # mouse wheel
Start-Sleep -s 11

bat,PowerShell ,windows

Posted by eightban