5 - 参考函数-API

5.1 鼠标管理

a). MouseClick 点击鼠标

MouseClick ( "button" [, x, y [, clicks = 1 [, speed = 10]]] )
示例:MouseClick($MOUSE_CLICK_LEFT)
The button to click:    Constants are defined in "AutoItConstants.au3".
    $MOUSE_CLICK_LEFT ("left")
    $MOUSE_CLICK_RIGHT ("right")
    $MOUSE_CLICK_MIDDLE ("middle")
    $MOUSE_CLICK_MAIN ("main")
    $MOUSE_CLICK_MENU ("menu")
    $MOUSE_CLICK_PRIMARY ("primary")
    $MOUSE_CLICK_SECONDARY ("secondary")

speed   1(fastest)~100(slowest)

b). MouseClickDrag //按下鼠标并拖动

//注:到目的地后会松开,登陆滑块需要使用keydown/keyup
MouseClickDrag ( "button", x1, y1, x2, y2 [, speed = 10] )

示例:MouseClickDrag($MOUSE_CLICK_LEFT, 0, 200, 600, 700)
button
    The button to click:    Constants are defined in "AutoItConstants.au3".
        $MOUSE_CLICK_RIGHT ("right")
        $MOUSE_CLICK_MIDDLE ("middle")
        $MOUSE_CLICK_MAIN ("main")
        $MOUSE_CLICK_MENU ("menu")
        $MOUSE_CLICK_PRIMARY ("primary")
        $MOUSE_CLICK_SECONDARY ("secondary")
x1, y1 The x/y coords to start the drag operation from. 
x2, y2 The x/y coords to end the drag operation at. 
speed   1(fastest)~100(slowest)

c). MouseDown MouseDown ( "button" ) //当前位置按下鼠标

示例: MouseDown($MOUSE_CLICK_LEFT) ; Set the left mouse button state as down.
        Sleep(100)
        MouseUp($MOUSE_CLICK_LEFT) ; Set the left mouse button state as up.
The button to click:    Constants are defined in "AutoItConstants.au3".
    $MOUSE_CLICK_RIGHT ("right")
    $MOUSE_CLICK_MIDDLE ("middle")
    $MOUSE_CLICK_MAIN ("main")
    $MOUSE_CLICK_MENU ("menu")
    $MOUSE_CLICK_PRIMARY ("primary")
    $MOUSE_CLICK_SECONDARY ("secondary")

d). MouseUp ( "button" ) //松开指定鼠标键
e). MouseGetPos MouseGetPos ( [dimension] ) //当前鼠标位置,返回数组,X/Y坐标

Local $aPos = MouseGetPos()

f). MouseMove MouseMove ( x, y [, speed = 10] ) //移动鼠标

示例:MouseMove(700, 700, 0) ;
speed   1(fastest)~100(slowest)

g). MouseWheel MouseWheel ( "direction" [, clicks = 1] ) //滑动鼠标滚轮

示例:MouseWheel($MOUSE_WHEEL_UP, 10)
The direction to move the wheel:    Constants are defined in "AutoItConstants.au3".
    $MOUSE_WHEEL_UP ("up")
    $MOUSE_WHEEL_DOWN ("down")
clicks [optional] The number of times to move the wheel. Default is 1. 

5.2 windows窗口管理

a). WinActivate ( "title" [, "text"] ); //激活指定窗口(焦点)
b). WinActive ( "title" [, "text"] ) //窗口是否存在,且激活状态
c). WinClose ( "title" [, "text"] ) //关闭窗口
d). WinExists ( "title" [, "text"] ) //窗口是否存在
e). WinGetHandle ( "title" [, "text"] ) //获取窗口句柄
f). WinGetProcess ( "title" [, "text"] ) //窗口对应的进程Id
g). WinGetState ( "title" [, "text"] ) //窗口状态

返回值: 
Success: a value indicating the state of the window. Multiple values are added together so use BitAND() to examine the part you are interested in:
    $WIN_STATE_EXISTS (1) = Window exists
    $WIN_STATE_VISIBLE (2) = Window is visible
    $WIN_STATE_ENABLED (4) = Window is enabled
    $WIN_STATE_ACTIVE (8) = Window is active
    $WIN_STATE_MINIMIZED (16) = Window is minimized
    $WIN_STATE_MAXIMIZED (32) = Window is maximized 
Failure: 0 and sets the @error flag to non-zero if the window is not found. 
//示例代码
    Local $iState = WinGetState($hWnd)
    ; Check if the Notepad window is minimized and display the appropriate message box.
    If BitAND($iState, 16) Then

h). WinKill ( "title" [, "text"] ) //强制关闭
i). WinList ( ["title" [, "text"]] ) //已打开的窗口列表
j). WinWait ( "title" [, "text" [, timeout = 0]] ) //等待直到指定窗口出现

    返回值:
    The array returned is two-dimensional and is made up as follows:
        $aArray[0][0] = Number of windows returned
        $aArray[1][0] = 1st window title
        $aArray[1][1] = 1st window handle (HWND)
        $aArray[2][0] = 2nd window title
        $aArray[2][1] = 2nd window handle (HWND)
//示例-展示所有窗口
#include <MsgBoxConstants.au3>
Example()
Func Example()
    ; Retrieve a list of window handles.
    Local $aList = WinList()

    ; Loop through the array displaying only visable windows with a title.
    For $i = 1 To $aList[0][0]
        If $aList[$i][0] <> "" And BitAND(WinGetState($aList[$i][1]), 2) Then
            MsgBox($MB_SYSTEMMODAL, "", "Title: " & $aList[$i][0] & @CRLF & "Handle: " & $aList[$i][1])
        EndIf
    Next
EndFunc 

k). WinWaitActive ( "title" [, "text" [, timeout = 0]] ) //等待直到指定窗口激活
l). WinWaitClose ( "title" [, "text" [, timeout = 0]] ) //等待直到指定窗口不存在
m). WinWaitNotActive ( "title" [, "text" [, timeout = 0]] ) //等待直到指定窗口非激活状态
n). WinSetState ( "title", "text", flag ) //设置窗口状态,显示,隐藏,最大化,最小化等

示例代码: WinSetState($hWnd, "", @SW_HIDE)
The "show" flag of the executed program:
    @SW_HIDE = Hide window
    @SW_SHOW = Shows a previously hidden window
    @SW_MINIMIZE = Minimize window
    @SW_MAXIMIZE = Maximize window
    @SW_RESTORE = Undoes a window minimization or maximization
    @SW_DISABLE = Disables the window
    @SW_ENABLE = Enables the window

转载于:https://www.cnblogs.com/Desneo/p/7352020.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值