求帮忙用VB编一个鼠标键盘连点的小程序!~
谁能帮我用vb编一个小程序按F11开启和停止每2秒钟,鼠标“左键”和键盘“Enter”自动点击一次最好能把源工程发给我,谢谢!~或者直接把语言剪贴回复给我也可以~...
谁能帮我用vb编一个小程序
按F11开启和停止
每2秒钟,鼠标“左键”和键盘“Enter”自动点击一次
最好能把源工程发给我,谢谢!~
或者直接把语言剪贴回复给我也可以~ 展开
按F11开启和停止
每2秒钟,鼠标“左键”和键盘“Enter”自动点击一次
最好能把源工程发给我,谢谢!~
或者直接把语言剪贴回复给我也可以~ 展开
展开全部
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)'声名API
'定义变量:
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
Private Sub Command1_Click()
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '鼠标左键单击事件
End Sub
Private Sub Command2_Click()
mouse_event MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0 '鼠标右键单击事件
End Sub
Private Sub Command3_Click()
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
'-------------------------------------'两次连续的鼠标左键单击事件 构成一次鼠标双击事件
End Sub
'================================前台模拟================================
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long'-查找父句柄
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long'-查找子句柄
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long'-Post后台消息
Private Const BM_CLICK = &HF5 '定义单击常量
Private Sub Form_Load()
Shell "calc.exe" '打开机算器
End Sub
Private Sub Command1_Click()
Dim a As Long
Dim b As Long
a = FindWindow(vbNullString, "计算器") '查找父句柄
b = FindWindowEx(a, 0, vbNullString, "1") '查找子句柄,也就是按扭1这个句柄
PostMessage b, BM_CLICK, 0, 0 '单击按钮
End Sub
'================================后台模拟================================
'以下是键盘模拟
Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As GENERALINPUT, ByVal cbSize As Long) As Long
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Type GENERALINPUT
dwType As Long
xi(0 To 23) As Byte
End Type
Type KEYBDINPUT
wVk As Integer
wScan As Integer
dwFlags As Long
time As Long
dwExtraInfo As Long
End Type
Const INPUT_KEYBOARD = 1
Sub MySendKey(bkey As Long)
'参数bkey传入要模拟按键的虚拟码即可模拟按下指定键
Dim GInput(0 To 1) As GENERALINPUT
Dim KInput As KEYBDINPUT
KInput.wVk = bkey '你要模拟的按键
KInput.dwFlags = 0 '按下键标志
GInput(0).dwType = INPUT_KEYBOARD
CopyMemory GInput(0).xi(0), KInput, Len(KInput) '这个函数用来把内存中KInput的数据复制到GInput
KInput.wVk = bkey
KInput.dwFlags = KEYEVENTF_KEYUP ' 释放按键
GInput(1).dwType = INPUT_KEYBOARD ' 表示该消息为键盘消息
CopyMemory GInput(1).xi(0), KInput, Len(KInput)
'以上工作把按下键和释放键共2条键盘消息加入到GInput数据结构中
SendInput 2, GInput(0), Len(GInput(0)) '把GInput中存放的消息插入到消息列队
End Sub
'===============================================以上在模块中==============================================================
'===============================================以下在窗体中==============================================================
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Text1.SetFocus
'Sleep 1000
Call MySendKey(2) '2为虚拟码
End Sub
'虚拟码: http://baike.baidu.com/link?url=p7B5X-v2RweBEFQo44pWWrb1Ac0mNFfmObRZTbSuVMGx6VgV55Fdf-3ppkzq8F0y
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询