VB模拟组合键

PostMessag无法模拟组合键,它似乎是发送一个按键以后才发送第二个!我试了不释放按键,还是没有效果!keybd_event似乎不可以向指定窗口发送呢。。还有别的方法... PostMessag无法模拟组合键,它似乎是发送一个按键以后才发送第二个!我试了不释放按键,还是没有效果!

keybd_event 似乎不可以向指定窗口发送呢。。 还有别的方法吗?

我要向指定窗口发送组合键
请各位高手帮忙
展开
 我来答
远风的梦想家
2010-08-02 · TA获得超过2550个赞
知道大有可为答主
回答量:1389
采纳率:0%
帮助的人:0
展开全部
'这个代码在记事本上验证是可以的,动作是按ALT+F,但是不保证在游戏里是可以的,因为游戏里有些窗口是接收不到你的按键消息的,还有一些屏蔽了sendmessage这些动作,不明白的百度HI我吧

ALT键的消息跟别的不一样,其它组合键也不是那种你不发送弹起就可以的,要增加一个特殊的标志位才可以
Option Explicit
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
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 Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101

Private Const WM_SYSKEYDOWN = &H104

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 Sub Command1_Click()
Dim jsb As Long
jsb = FindWindow("notepad", vbNullString)
Dim mhwnd As Long
mhwnd = FindWindowEx(jsb, 0, "edit", vbNullString)

PostMessage mhwnd, WM_SYSKEYDOWN, vbKeyF, &H20000000

End Sub

Private Function makelparam(ByVal VirtualKey As Long, ByVal flag As Boolean) As Long
Dim s As String
Dim Firstbyte As String 'lparam参数的24-31位
If flag = False Then 'keydown
Firstbyte = "00"
Else
Firstbyte = "C0" 'keyup
End If
Dim Scancode As Long
'获得虚拟键扫描码
Scancode = MapVirtualKey(VirtualKey, 0)
Dim Secondbyte As String 'lparam参数的16-23位,即虚拟键扫描码
Secondbyte = Right("00" & Hex(Scancode), 2)
s = Firstbyte & Secondbyte & "0001" '0001为lparam参数的0-15位,即发送次数
makelparam = Val("&H" & s)
End Function
承奇水gt
2010-08-02 · TA获得超过514个赞
知道小有建树答主
回答量:264
采纳率:0%
帮助的人:151万
展开全部
提供给你一个思路,用全局钩子(hook技术),可以全局模拟按键,用keybd_event就可以实现。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式