求一个VB按键编程

F9开始按F5键,F10停止按F5键非活动窗下可以继续按键... F9开始按F5键,F10停止按F5键 非活动窗下可以继续按键 展开
 我来答
zhenghanxi
2008-05-25 · TA获得超过422个赞
知道小有建树答主
回答量:268
采纳率:0%
帮助的人:255万
展开全部
注册热键F9,F10,用来控制时间控件的可用性,时间控件sendkeys 发送F5键

'新建窗体,添加timer1,设置其interval属性调整发送按键的频率
’以下保存在模块.bas中,
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
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
Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fskey_Modifiers As Long, ByVal vk As Long) As Long
Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long) As Long
Public Const GWL_WNDPROC = (-4)
Public Const WM_HOTKEY = &H312
Public preWinProc As Long
Public Function wndproc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_HOTKEY Then
If wParam = 0 Then Form1.Timer1.Enabled = True
If wParam = 1 Then Form1.Timer1.Enabled = False
End If
wndproc = CallWindowProc(preWinProc, hwnd, Msg, wParam, lParam)
End Function

'以下保存在窗体中
Private Sub Form_Load()
preWinProc = GetWindowLong(Me.hwnd, GWL_WNDPROC) '获得窗口过程的地址
SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf wndproc '为窗口过程设定一个新的地址
RegisterHotKey Me.hwnd, 0, 0, vbKeyF9
RegisterHotKey Me.hwnd, 1, 0, vbKeyF10 '登记热键
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnregisterHotKey Me.hwnd, 0
UnregisterHotKey Me.hwnd, 1 '释放先前登记的热键
SetWindowLong Me.hwnd, GWL_WNDPROC, preWinProc '还原窗口过程地址
End Sub
Private Sub Timer1_Timer()
SendKeys vbKeyF5
End Sub
a5826190
2008-05-24 · TA获得超过424个赞
知道小有建树答主
回答量:750
采纳率:0%
帮助的人:270万
展开全部
F1键: VK_F1 (112)
F2键: VK_F2 (113)
F3键: VK_F3 (114)
F4键: VK_F4 (115)
F5键: VK_F5 (116)
F6键: VK_F6 (117)
F7键: VK_F7 (118)
F8键: VK_F8 (119)
F9键: VK_F9 (120)
F10键: VK_F10 (121)
F11键: VK_F11 (122)
F12键: VK_F12 (123)

做个键盘事件
i=chr(116)
if Asciikey=120 then
sendkey="{"i"}"
if Asciikey=121 then
i=0
没试过 大概是这样吧
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式