当前位置:编程学习 > VB >>

VB自动按按键 高手来

我玩DNF中的战斗法师,刷图时总是要按  F(炫纹发射)  累啊

我刚学VB  想做个自动按按键的程序

要求 "程序最小化到系统托盘" , "当按下 A,S,G,H. 时自动按F" , "尽量不要太浪费系统资源,电脑很烂" , "带有 设置 按钮,可以设置按键的,防止以后改按键还要重新编写程序"

大侠帮帮我吧

[[[成功后给50分]]]

补充:DNF    '地下城与勇士 游戏
追问:不用避免

就算一次按 A`S`G`H` 也要传递4次到F

帮忙改一下

谢谢大侠

答案: 

为了避免每次按H键都发送F键,可以用G键做标记

 

1.G键标记

2.H键发送F键

 

程序代码如下:

 

Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fskey_Modifiers As Long, ByVal vk As Long) As Long
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long) As Long

Public Const WM_HOTKEY = &H312
Public Const MOD_ALT = &H1
Public Const MOD_CONTROL = &H2
Public Const MOD_SHIFT = &H4
Public Const GWL_WNDPROC = (-4)
Public preWinProc As Long
Public Modifiers As Long, uVirtKey1 As Long, idHotKey As Long
Public vKey As Boolean 'G键标记
Public Function SetHotKey()
preWinProc = GetWindowLong(FrmMid.hwnd, GWL_WNDPROC)
SetWindowLong FrmMid.hwnd, GWL_WNDPROC, AddressOf Keywndproc
RegisterHotKey FrmMid.hwnd, 1, 0, vbKeyG   '注册热键G
RegisterHotKey FrmMid.hwnd, 2, 0, vbKeyH  '注册热键H
End Function

Public Function Keywndproc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_HOTKEY Then
Select Case wParam
Case 1  '检测到按下G
    vKey = True
Case 2 '检测到按下H
 If vKey = True Then

       SendKeys "F" '模拟发送F键

       vKey = False

  End If
End Select
End If
Keywndproc = CallWindowProc(preWinProc, hwnd, Msg, wParam, lParam)
End Function

 

Private Sub Form_Load()
vKey = False
 call SetHotKey() '程序启动时注册热键
End Sub

 

 

DNF 虾米东东?

 

keyDown事件下写

 

  

何必那么麻烦呢?用按键精灵不就行了。。
keyDown知道吧,不知道的话你是做不出来的

这个只能编个全局的HOOK了。

VB没法做的吧.VB如果程序不是激活状态则无法响影用户的事件

上一个:学C语言需要有VB的基础吗?
下一个:求下列VB练习复习题答案

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,