如何用VB实现模拟按ctrl键同时按下鼠标左键,从而控制后台程序?

不是指用mouse_down事件的方法。而是要求用VB自动按ctrl键同时按下鼠标左键,从而控制后台程序。如下我用了四个方案,但都没有成功,请大虾们指导:'mouse_e... 不是指用mouse_down事件的方法。而是要求用VB自动按ctrl键同时按下鼠标左键,从而控制后台程序。
如下我用了四个方案,但都没有成功,请大虾们指导:

'mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
'SendKeys 17 'vbKeyConterol '17 Ctrl 键
' mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
' mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
'SendKeys 17 'vbKeyConterol '17 Ctrl 键
'mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0

GetCursorPos tPoint1 '获得当前鼠标位置
hWin = WindowFromPoint(tPoint1.X, tPoint1.Y) '获得窗口名柄
SendKeys "{^}"

PostMessage hWin, WM_KEYDOWN, &H17, &H10001 ' 模拟按下 VK_Ctrl 键
''keybd_event VK_Ctrl, 0, 0, 0 '按下Ctrl键
' keybd_event VK_C, 0, 0, 0 '按下C键
' Delay 600 '延迟 毫秒。'
'PostMessage hWin, MOUSEEVENTF_RIGHTDOWN, 0, &H10001 ' 模拟按下 VK_Ctrl 键
SendKeys "{^}"

mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
'SendKeys 17 'vbKeyConterol '17 Ctrl 键
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
' PostMessage hWin, MOUSEEVENTF_RIGHTUP, 0, &HC0010001 ' 模拟抬起 VK_Ctrl 键 VK_Ctrl=&H17
' keybd_event VK_C, 0, KEYEVENTF_KEYUP, 0 '释放C键
' keybd_event VK_Ctrl, 0, KEYEVENTF_KEYUP, 0 '释放Ctrl键
SendKeys "{^}"
PostMessage hWin, WM_KEYUP, &H17, &HC0010001 ' 模拟抬起 VK_Ctrl 键 VK_Ctrl=&H17
SendMessage等方案均已试用过,均未果。可能是键盘CTRL加鼠标的方式还有其它不同?
请大虾们劳神试验一样,再将VB源码贴出来,大家都会感激您。
展开
 我来答
匿名用户
2010-05-27
展开全部
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
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim anctlejiang As Long '这句写到通用里
Private Sub Command1_Click()
PostMessage 65674, 100, 17, 0 '这个是按下CTLE键
anctlejiang = 1

Sleep 1000 '延迟1秒
PostMessage 65674, 101, 17, 0 '弹起CTLE键
anctlejiang = 0
End Sub

Private Sub Timer1_Timer()
MsgBox anctlejiang
If anctlejiang <> 0 Then
Dim aa As Long
PostMessage 65674, 201, 1, 0 '这个是按下左键
Label1.Caption = "以按下左键"
aa = anctlejian
If aa <> anctlejian Then
PostMessage 65674, 202, 1, 0 '弹起左键
Label1.Caption = "以弹起左键"
End If
End If
End Sub
Coo_boi
2010-05-16 · TA获得超过1333个赞
知道大有可为答主
回答量:2209
采纳率:50%
帮助的人:220万
展开全部
API Fucntion:
SendMessage
But must point at a Object.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式