0
2

More than 3 years have passed since last update.

フルフルマウス

Last updated at Posted at 2021-01-21

マウスを一定時間で移動させるコマンド

間違っても悪用してはいけません!!!
一定時間操作しないとスクリーンセイバーが邪魔な時とかありますよね?そういう人向けですよ?
このコードを使用によるいかなる損害も責任は取れませんのでご了承ください。

参考サイト:

ソースコード

マウスフルフル.ps1
# カーソルを動かす為に必要
add-type -AssemblyName System.Windows.Forms

#Win32のDLLインポート
$signature=@' 
     [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
     public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
'@

#Win32のイベントを拾う準備
$SendMouseEvent = Add-Type -memberDefinition $signature -name "Win32MouseEventNew" -namespace Win32Functions -passThru

#画面上に出すメッセージ
echo "Ctrl+Cで終了します。"

# マウス移動
$MOUSEEVENTF_MOVE = 0x00000001

# スリープ秒数
$SleepSec = 5

# マウスの振れ幅
# ・マウスの移動イベント生成用の振れ幅
$MoveMouseDistance = 10
# ・マウスの座標を左右にずらす用の振れ幅
$MoveMouseDistanceX = 10

# 偶数回数目は左へ、奇数回数目で右へずらすためのフラグ
$Flag = $true

# 無限ループ
while ($true) {
   # スリープ
   Start-Sleep $SleepSec

   # 現在のカーソルの位置を取得
   $x = [System.Windows.Forms.Cursor]::Position.X
   $y = [System.Windows.Forms.Cursor]::Position.Y

   # 座標左にずらす(マウスイベントを監視するOS(スクリーンセーバー、スリープ)対策)
   $SendMouseEvent::mouse_event($MOUSEEVENTF_MOVE, -$MoveMouseDistance, 0, 0, 0)

   # 座標右にずらす(マウスイベントを監視するOS(スクリーンセーバー、スリープ)対策)
   $SendMouseEvent::mouse_event($MOUSEEVENTF_MOVE, $MoveMouseDistance, 0, 0, 0)

   # 座標を監視するアプリ対策(座標を左か右に1ピクセル分ずらすだけにする)
   if ($Flag) {
       $x += $MoveMouseDistanceX
       $Flag = $false;
   }
   else {
       $x -= $MoveMouseDistanceX
       $Flag = $true
   }
   [System.Windows.Forms.Cursor]::Position = new-object System.Drawing.Point($x, $y)
   $x = [System.Windows.Forms.Cursor]::Position.X
   $y = [System.Windows.Forms.Cursor]::Position.Y
}
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2