首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

怎么使用vb.net2005实现带快捷键功能的程序

2012-02-16 
如何使用vb.net2005实现带快捷键功能的程序我现在在用vb.net2005做一个程序,想实现快捷键的功能,但却不知

如何使用vb.net2005实现带快捷键功能的程序
我现在在用vb.net   2005做一个程序,想实现快捷键的功能,但却不知如何下手……望高手指点,谢谢!

[解决办法]
你可以参考这篇,说得很详细了.
http://www.seeitco.com/doc/Html/Delphi/205723167.html
实现一个热键注册编辑的类

////////////////////////////////////////////////////////////////////
Public Class Form1
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 Declare Auto Function RegisterHotKey Lib "user32.dll " Alias _
"RegisterHotKey " (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Boolean
Public Declare Auto Function UnRegisterHotKey Lib "user32.dll " Alias _
"UnregisterHotKey " (ByVal hwnd As IntPtr, ByVal id As Integer) As Boolean

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RegisterHotKey(Handle, 0, MOD_CONTROL, Asc( "T "))
End Sub

Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
UnregisterHotKey(Handle, 0)
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_HOTKEY Then
If Visible Then
Hide()
Else
Show()
End If
End If
MyBase.WndProc(m)
End Sub
End Class

[解决办法]
(&S) 你是要类似于这样的东西?
在 空间的text属性上加(&S) S是你要设置的快捷键
别忘记给分啊。。
[解决办法]
有点麻烦,么懂
[解决办法]
把窗体 KeyPreview 设置为 True
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.Space Then
Me.Button1_Click(sender, e)
End If
End Sub
[解决办法]
mark

[解决办法]
Private hHook As Integer = 0
Private HookProc As CallBack
Public hnexthookproc As Integer

Declare Function GetCurrentThreadId Lib "kernel32 " Alias "GetCurrentThreadId " () As Integer

Declare Function SetWindowsHookEx Lib "user32 " Alias "SetWindowsHookExA " (ByVal idHook As HookType, ByVal lpfn As CallBack, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer

Declare Function UnhookWindowsHookEx Lib "user32 " (ByVal hHook As Integer) As Integer

Declare Function CallNextHookEx Lib "user32 " (ByVal hHook As Integer, ByVal ncode As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

Public Delegate Function CallBack(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer


Public Enum HookType
WH_KEYBOARD = 2
End Enum

Public Sub UnHook() '解Hook
If hnexthookproc <> 0 Then
UnhookWindowsHookEx(hnexthookproc)
hnexthookproc = 0
End If
End Sub

Public Function SetHook() '设置Hook
If hnexthookproc <> 0 Then


Exit Function
End If

HookProc = New CallBack(AddressOf MyKeyboardProc)
hHook = SetWindowsHookEx(HookType.WH_KEYBOARD, HookProc, IntPtr.Zero, GetCurrentThreadId)
Return hHook

End Function

Public Function MyKeyboardProc(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

MyKeyboardProc = 0

If nCode < 0 Then
MyKeyboardProc = CallNextHookEx(hnexthookproc, nCode, wParam, lParam)
Exit Function
End If

'拦截的是Key_Down事件
If lParam > 0 Then
'获取击键示例
If wParam = Keys.Space Then
'在这里键入你的代码
ElseIf wParam = Keys.Left Then
'在这里键入你的代码
ElseIf wParam = Keys.Right Then
'在这里键入你的代码
ElseIf wParam = Keys.Up Then
'在这里键入你的代码
ElseIf wParam = Keys.Down Then
'在这里键入你的代码
End If
MyKeyboardProc = 1
End If

End Function

热点排行