主题:[讨论]如何在另一个程序的窗口中进行简单操作?
xuehu90
[专家分:40] 发布于 2009-06-01 19:42:00
请问各位大侠,有一个客户端程序,在连接到服务器之后,需要每隔一分钟就在它的窗口上点击一次(或者鼠标滚轮滚动一次),才能够保证它持续计时,请问可不可以写一个程序自动的每隔一段时间就在这个窗口中进行一次上述操作?我知道也许要用一个timer控件,那么应该用什么样的语句来实现呢?如能提供核心部分代码,不胜感激!
回复列表 (共2个回复)
沙发
xuehu90 [专家分:40] 发布于 2009-06-02 22:21:00
大家怎么都只看不回啊,算了,我自问自答,把它写在这里。
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Const MOUSEEVENTF_LEFTDOWN = &H2 '左键按下
Const MOUSEEVENTF_LEFTUP = &H4 '左键弹起
Const MOUSEEVENTF_MIDDLEDOWN = &H20 '滚轮按下
Const MOUSEEVENTF_MIDDLEUP = &H40 '
Const MOUSEEVENTF_MOVE = &H1 '移动
Const MOUSEEVENTF_ABSOLUTE = &H8000 '
Const MOUSEEVENTF_RIGHTDOWN = &H8 '右键
Const MOUSEEVENTF_RIGHTUP = &H10 '上面鼠标事件 API
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long '鼠标移动
Private Sub Timer1_Timer()
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0 '鼠标事件
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
SetCursorPos 512, 380 '鼠标移动 坐标等于分辨率
End Sub
板凳
老大徒伤悲 [专家分:29120] 发布于 2009-06-03 14:57:00
谢谢
我来回复