VB 从零开始编外挂(三)
躲避了NP的扫描现在就可以模拟了!
需要VB API函数:
keybd_event ←函数模拟了键盘行动
相关API声明:
keybd_event
↓
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal Scan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
需要的控件:Timer(interval不为空)
代码:
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal Scan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Timer1_Timer()
Call keybd_event(82, 0, 0, 0) '模拟按下"R"键
End Sub
其它模拟:
方法一:
AppActivate sTitle
SendKeys "5"
方法二:
AppActivate sTitle
SendKeys vbKey5
方法三:
SendMessage Hwnd, WM_KEYDOWN, vbKey5, 0&
SendMessage Hwnd, WM_KEYUP, vbKey5, 0&
方法四:
AppActivate sTitle
keybd_event 53, 0, 0, 0
keybd_event 53, 0, KEYEVENTF_KEYUP, 0
方法五:
PostMessage lHwnd, WM_KEYDOWN, vbKey5, 0&
PostMessage lHwnd, WM_KEYUP, vbKey5, 0&
VB 从零开始编外挂(四)
添加快捷键
需要VB API函数:
GetAsyncKeyState ←判断函数调用时指定虚拟键的状态
相关API声明:
GetAsyncKeyState
↓
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
Private Function MyHotKey(vKeyCode) As Boolean
需要的控件:Timer(interval不为空)
代码:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
Private Function MyHotKey(vKeyCode) As Boolean
MyHotKey = (GetAsyncKeyState(vKeyCode) < 0)
End Function
'然后在循环中或Timer的Timer事件中检测:
Private Sub Timer1_Timer()
If MyHotKey(vbKeyA) And vbKeyControl Then 'ctrl+A
End '关闭
End If
'其中vbkeyA是键盘″A″的常数,其他键可按F1查得。
End Sub
其它方法:
比如按下"ctrl+A"就退出!
'可以设置Form的KeyPreview属性为True,然后在Form_KeyDown事件中添加代码:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = Asc("A") And Shift = vbCtrlMask Then unload me '如果ctrl+A键被按下就退出
End Sub
文章来源于领测软件测试网 https://www.ltesting.net/