找回密码
 加入
搜索
查看: 5197|回复: 9

不需要移动鼠标到已知位置,直接执行鼠标左键单击操作..[已解决]

[复制链接]
发表于 2008-7-10 15:15:08 | 显示全部楼层 |阅读模式
查了些资料.没有找到如题的功能..也没有好的思路完成,

就是...要在某处鼠标单击,但必须把鼠标移过去单击..(这个鼠标移过去难免就要影响到操作,比如正在玩鼠标操作的游戏..)

问题是,怎么样可以略过鼠标移过去这个步骤啊?

[ 本帖最后由 e5907 于 2008-7-10 15:36 编辑 ]
 楼主| 发表于 2008-7-10 15:36:19 | 显示全部楼层
已经找到.....在官方论坛...


#NoTrayIcon
#Include <GuiToolBar.au3>

_SysTray_ClickItem("音量", "left", 2)

;====================================================================================
;
;Function Name:    _SysTray_ClickItem()
;Description:      Click on item in Windows system tray by any substring in the title
;Parameters:       $iTitle - The title of the item in Windows system tray (you can see the title of the item when mouse cursor hovered on item).
;                  $iButton - [optional] The button to click, "left" or "right". Default is the left button.
;                  $iClick - [optional] The number of times to click the mouse. Default is 2
;                  
;Return Value(s):  None
;Requirement(s):   AutoIt 3.2.10.0
;
;
;Autor(s):        R.Gilman (a.k.a rasim); Siao (Thanks for idea )
;
;====================================================================================
Func _SysTray_ClickItem($iTitle, $iButton = "left", $iClick = 2)
    Local $hToolbar, $iButCount, $aRect, $i
    
    If Not $iTitle Then
        MsgBox(16, "Error", "Please indicate title")
        Return 0
    EndIf
    
    $hToolbar = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Return 0
    EndIf
    
    $iButCount = _GUICtrlToolbar_ButtonCount($hToolbar)
    If $iButCount = 0 Then
        MsgBox(16, "Error", "Not found item in system tray")
        Return
    EndIf
    
    For $i = 0 To $iButCount - 1
        $cID = _GUICtrlToolbar_IndexToCommand($hToolBar, $i)
        If StringInStr(_GUICtrlToolbar_GetButtonText($hToolBar, $i), $iTitle) Then
            $aRect = _GUICtrlToolbar_GetButtonRect($hToolBar, $i)
            ControlClick("[Class:Shell_TrayWnd]", "", "ToolbarWindow321", $iButton, $iClick, $aRect[0], 5)
            $aRect = 0
            Return 1
        EndIf
    Next
    MsgBox(48, "Fail", "Required item not found")
EndFunc

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 1金钱 +2 收起 理由
kakinkgb + 2 实用

查看全部评分

发表于 2008-9-6 19:33:19 | 显示全部楼层
  我发现用上例脚本会找不到图标。具体情况如下:
  如系统托盘有三个图标,系统内部顺序为1.音量、2瑞星、3游戏(可由函数输出得知顺序),当关闭顺序靠前的音量图标后,不运行其它加载图标的程序,此时_GUICtrlToolbar_ButtonCount函数结果是2,_GUICtrlToolbar_GetButtonText($hToolBar, 0)结果为空,_GUICtrlToolbar_GetButtonText($hToolBar, 1)结果为"瑞星",_GUICtrlToolbar_GetButtonText($hToolBar,2)结果为“游戏”。上例从0循环到1结束,找不到“游戏”图标。
  不知是系统托盘工作原理就是这样,还是函数的原因,当顺序靠前的图标退出,仅仅是把该位置清空,并没有把后续位置图标前移,而_GUICtrlToolbar_ButtonCount函数统计出的数量又是正确的。所以如果用_GUICtrlToolbar_ButtonCount结果减1来循环,结果肯定是错误的。
  我最终用了w循环,在循环内检测_GUICtrlToolbar_GetButtonText结果是否为空,非空计数达到_GUICtrlToolbar_ButtonCount结果时再退出循环。
发表于 2008-10-4 21:13:28 | 显示全部楼层
superqvb
能不能把你改W循环的贴出来,我不太会呀
发表于 2009-4-12 00:43:24 | 显示全部楼层
强帖留名......
发表于 2009-8-17 21:14:26 | 显示全部楼层
2楼的脚本 并不能百分百正确点到图标,特别是改成右键单击的话,正确点击到的概率估计只有50%。
发表于 2009-9-26 13:27:34 | 显示全部楼层
可以改成单击一次,然后捕捉弹出来的音量,再点击静音,这样又怎样写呢?
发表于 2009-10-24 22:45:31 | 显示全部楼层
嗯,是啊!
发表于 2011-2-8 00:55:14 | 显示全部楼层
概率只有50%。
发表于 2012-2-9 11:30:00 | 显示全部楼层
看看帮助,用send命令,有专门调节音量的键
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-12 09:29 , Processed in 0.083170 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表