MouseClickDrag

指定したマウスボタンをクリックしたまま、移動先の座標にマウスを移動し、ボタンを離します。

MouseClickDrag WhichButton, X1, Y1, X2, Y2 , Speed, Relative

パラメータ

WhichButton

型:文字列

If blank or omitted, it defaults to Left (the left mouse button). Otherwise, specify Left, Right, Middle (or just the first letter of each of these); or X1 (fourth button) or X2 (fifth button). 事例:MouseClickDrag "X1", 0, 0, 10, 10.

左はプライマリーボタン、右はセカンダリーボタンに対応します。ユーザーがシステム設定でボタンを入れ替えると、ボタンの物理的な位置は入れ替わりますが、効果は変わりません。

X1, Y1

型:整数

Specify the X and Y coordinates of the drag's starting position (the mouse will be moved to these coordinates right before the drag is started). Coordinates are relative to the active window's client area unless CoordMode was used to change that.

[v2.0.7+]: If both X1 and Y1 are omitted, the mouse cursor's current position is used. Due to a bug, X1 and Y1 were mandatory in previous versions.

X2, Y2

型:整数

The X and Y coordinates to drag the mouse to (that is, while the button is held down). Coordinates are relative to the active window's client area unless CoordMode was used to change that.

Speed

型:整数

省略された場合、デフォルトの速度(SetDefaultMouseSpeedで設定されたもの、またはそれ以外の2)が使用されることになります。Otherwise, specify the speed to move the mouse in the range 0 (fastest) to 100 (slowest). スピードを0にすると、マウスが瞬時に動きます。

SendInput/PlayモードではSpeedは無視され、マウスは瞬時に移動します(ただし、SetMouseDelayにはSendPlayに適用されるモードがあります)。To visually move the mouse more slowly -- such as a script that performs a demonstration for an audience -- use SendEvent "{Click 100 200}" or SendMode "Event" (optionally in conjuction with BlockInput).

Relative

型:文字列

If blank or omitted, the X and Y coordinates will be used for absolute positioning. Otherwise, specify the following letter:

R:X1、Y1座標は、現在のマウス位置からのオフセットとして扱われます。つまり、カーソルは現在位置から右にX1ピクセル(マイナスの場合は左)、下にY1ピクセル(マイナスの場合は上)だけ移動することになります。同様に、X2、Y2座標は、X1、Y1座標からのオフセットとして扱われます。例えば、次のようにすると、まずカーソルを開始位置から下と右に5ピクセル移動させ、その位置から下と右に10ピクセルずつドラッグします:MouseClickDrag "Left", 5, 5, 10, 10, , "R".

備考

SendModeで設定された送信方式を使用します。

Dragging can also be done via the various Send functions, which is more flexible because the mode can be specified via the function name. 事例:

SendEvent "{Click 6 52 Down}{click 45 52 Up}"

上記の方法のもう一つの利点は、MouseClickDragとは異なり、ユーザーがシステムのコントロールパネルでマウスの左右のボタンを入れ替えた場合に自動的に補正されることです。

SendPlayモードは、他のモードに比べ、より幅広いゲームにおいてマウスイベントを正常に発生させることができます。ただし、WordPadやMetapadなどのRichEditコントロールでは、SendPlayによるドラッグが効かない場合があります(他のコントロールも可能性があります)。

アプリケーションやゲームによっては、マウスの動きが速いと追従できないことがあります。speedパラメータまたはSetDefaultMouseSpeedを使用すると、速度を下げることができます(デフォルトのSendEventモードのみ)。

BlockInput関数を使用すると、ユーザーによる物理的なマウス操作が、マウス関数によって生成されるシミュレーションマウスイベントを妨害することを防ぐことができます。ただし、SendInput/Playモードでは、ユーザーの物理的なマウス操作を自動的に後回しにするため、一般にこの操作は必要ありません。

マウスのクリックダウンとクリックアップのたびに、自動的に遅延が発生します(SendInputモードは除く)。この遅延は、ドラッグ操作の際のマウスの移動後にも発生します。ディレイの長さを変更する場合は、SetMouseDelayを使用します。

CoordMode, SendMode, SetDefaultMouseSpeed, SetMouseDelay, Click, MouseClick, MouseGetPos, MouseMove, BlockInput

マウスの左ボタンをクリックしたまま、マウスカーソルを移動先の座標に移動させ、ボタンを離します。

MouseClickDrag "left", 0, 200, 600, 400

MS Paintを開き、小さな家を描きます。

Run "mspaint.exe"
if !WinWaitActive("ahk_class MSPaintApp",, 2)
    return
MouseClickDrag "L", 150, 450, 150, 350
MouseClickDrag "L", 150, 350, 200, 300
MouseClickDrag "L", 200, 300, 250, 350
MouseClickDrag "L", 250, 350, 150, 350
MouseClickDrag "L", 150, 350, 250, 450
MouseClickDrag "L", 250, 450, 250, 350
MouseClickDrag "L", 250, 350, 150, 450
MouseClickDrag "L", 150, 450, 250, 450