search 登录 注册
arrow_back返回列表
ID:42313
light_modedark_modedark_modedark_modestarstar
Lv.2 独赏二月雪
edit_note帖子 1,551
stars积分 20,071
event加入 2011-05-19
怀旧国机

VB从零开始写外挂3

schedule发表于 2013-06-19 18:29:00 visibility查看 184 chat_bubble回复 5
#1 楼主

--------------------------------------------------------------------------------------------------------------------------------------------------------
需要VB API函数:
GetAsyncKeyState ←判断函数调用时指定虚拟键的状态
--------------------------------------------------------------------------------------------------------------------------------------------------------
相关API声明:
GetAsyncKeyState

Private * Function GetAsyncKeyState Lib “user32“ (ByVal vkey As Long) As Integer
Private Function MyHotKey(vKeyCode) As Boolean
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要的控件:Timer(interval不为空)
--------------------------------------------------------------------------------------------------------------------------------------------------------
代码:
Private * 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

全部回复 (5)

ID:132793
light_modedark_modestarstar
Lv.7 可吟七步诗
2013-06-19 18:30:00 沙发
消除0回复
ID:1224
light_modedark_modedark_modestarstarstar
Lv.1 韶华一笑间
2013-06-19 18:44:00 板凳
谁来的?
ID:22222
light_modedark_modedark_modestar
Lv.4 莫问四书意
2013-06-19 18:56:00 地板
ID:107667
light_modestarstarstar
Lv.2 独赏二月雪
2013-06-19 20:28:00 #5
????
ID:136524
light_modedark_modestarstar
Lv.6 胸怀六国志
创世成员
2013-06-19 21:59:00 #6
额。。。
登录 后才能回复