GetCursorPos函數 獲取鼠標的位置
var
P: TPoint;
begin
GetCursorPos(P); //獲取鼠標位置
end;
SetCursorPos函數 設置鼠標的位置
var
x,y:integer; //
begin
x:=614; y:=282; //
SetCursorPos(x,y); //
Mouse_Event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); //開始點擊
Mouse_Event(MOUSEEVENTF_LEFTUP,0,0,0,0); //彈出
end;
mouse_event,用於模擬鼠標動作。無返回值。參數1類型:整數型(Integer),鼠標動作標識;參數2類型:整數型(Integer),鼠標動作的水平坐標X;參數3類型:整數型(Integer),鼠標動作的垂直坐標Y;參數4類型:整數型(Integer),鼠標滾輪轉動方向,若當前鼠標無滾輪動作,則取值為0;參數5在Windows SDK中的函數原型:
VOID mouse_event(
DWORD dwFlags, // flags specifying various motion/click variants 鼠標動作標識
DWORD dx, // horizontal mouse position or position change 鼠標動作的水平坐標
DWORD dy, // vertical mouse position or position change 鼠標動作垂直坐標
DWORD dwData, // amount of wheel movement 當鼠標動作標識為MOUSEEVENTF_WHEEL時,此參數為鼠標滾輪轉動方向,正值表示滾輪向前旋轉,遠離用戶;負值表示滾輪向后旋轉,向用戶。
DWORD dwExtraInfo // 32 bits of application-defined information 設定一個32位值用於取擴展信息
);
鼠標動作標識:
MOUSEEVENTF_MOVE = $0001; { mouse move 鼠標移動}
MOUSEEVENTF_LEFTDOWN = $0002; { left button down 左鍵按下}
MOUSEEVENTF_LEFTUP = $0004; { left button up 左鍵彈起}
MOUSEEVENTF_RIGHTDOWN = $0008; { right button down 右鍵按下}
MOUSEEVENTF_RIGHTUP = $0010; { right button up 右鍵彈起}
MOUSEEVENTF_MIDDLEDOWN = $0020; { middle button down 中間按下}
MOUSEEVENTF_MIDDLEUP = $0040; { middle button up 中鍵彈起}
MOUSEEVENTF_WHEEL = $0800; { wheel button rolled 滾輪移動}
MOUSEEVENTF_ABSOLUTE = $8000; { absolute move 絕對移動}
其他操作:
var
SDC: HDC;
SColor: COLORREF;
begin
//鼠標移動到坐標X:20 Y:30初
Mouse.CursorPos := Point(20, 30);
//獲取屏幕坐標X:20 Y:30初的顏色
SDC := GetDC(0);
SColor := GetPixel(SDC, 20, 30);
ReleaseDC(0, SDC);
//把取到的顏色畫在屏幕上
Canvas.Brush.Color := SColor;
Canvas.FillRect(Rect(0, 0, 50, 50));