vb中 虚拟键盘组合键alt+a的问题!
想在一个程序中发送alt+a的指令,我写了以下代码,可完全没反映!求各位帮帮忙好吗?是sendmenssage方法的!OptionExplicitPrivateDecla...
想在一个程序中发送alt+a的指令, 我写了以下代码,可完全没反映!求各位帮帮忙好吗?是sendmenssage方法的!
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 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("kkk", vbNullString)
Dim lParam As Long
lParam = makelparam(vbKeyMenu, False)
PostMessage jsb, WM_KEYDOWN, vbKeyMenu, lParam
lParam = makelparam(vbKeyA, False)
PostMessage jsb, WM_KEYDOWN, vbKeyA, lParam
lParam = makelparam(vbKeyA, True)
PostMessage jsb, WM_KEYUP, vbKeyA, lParam
lParam = makelparam(vbKeyMenu, True)
PostMessage jsb, WM_KEYUP, vbKeyMenu, lParam
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
其实呢 就是想 alt+a 实现 封神榜国际版中 自动猎杀的功能!按照梦想家大师的不行啊,
dir大师,你说 需要FindWindowEx来查找下一个句柄 如何呢 能做个吗?
kkk= fsonline class 下一个句柄 又是什么?
+qq 953341307
做到封神榜国际版中自动猎杀功能,调试通过 我倾家荡产了,也再所不辞!!170分 全给了! 展开
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 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("kkk", vbNullString)
Dim lParam As Long
lParam = makelparam(vbKeyMenu, False)
PostMessage jsb, WM_KEYDOWN, vbKeyMenu, lParam
lParam = makelparam(vbKeyA, False)
PostMessage jsb, WM_KEYDOWN, vbKeyA, lParam
lParam = makelparam(vbKeyA, True)
PostMessage jsb, WM_KEYUP, vbKeyA, lParam
lParam = makelparam(vbKeyMenu, True)
PostMessage jsb, WM_KEYUP, vbKeyMenu, lParam
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
其实呢 就是想 alt+a 实现 封神榜国际版中 自动猎杀的功能!按照梦想家大师的不行啊,
dir大师,你说 需要FindWindowEx来查找下一个句柄 如何呢 能做个吗?
kkk= fsonline class 下一个句柄 又是什么?
+qq 953341307
做到封神榜国际版中自动猎杀功能,调试通过 我倾家荡产了,也再所不辞!!170分 全给了! 展开
2个回答
展开全部
估计问题出在jsb = FindWindow("kkk", vbNullString),可能jsb并不是你的目标句柄,看这一句应该jsb应该是一个窗口的句柄,如果你要在这个窗口的某个部件(例如textbox)里执行CTRL^A,则需要FindWindowEx来查找下一个句柄
用vs自带工具spy检测一下,就知道下一个句柄什么,在调式环境下对下面的每一个句柄做PostMessage ,达到效果就知道哪一个句柄是你需要的
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
调用hw2& = FindWindowEx(0,hw1&, vbNullString, vbNullString)
hw1&指的父句炳
用vs自带工具spy检测一下,就知道下一个句柄什么,在调式环境下对下面的每一个句柄做PostMessage ,达到效果就知道哪一个句柄是你需要的
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
调用hw2& = FindWindowEx(0,hw1&, vbNullString, vbNullString)
hw1&指的父句炳
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询