1。把Form的KeyPreview设为True,
2。不明白
3。
Private Const MOD_ALT = &H1
Private Const MOD_CONTROL = &H2
Private Const MOD_SHIFT = &H4
Private Const PM_REMOVE = &H1
Private Const WM_HOTKEY = &H312
Private Type POINTAPI
    x As Long
    y As Long
End Type
Private Type Msg
    hWnd As Long
    Message As Long
    wParam As Long
    lParam As Long
    time As Long
    pt As POINTAPI
End Type
Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private bCancel As Boolean
Private Sub ProcessMessages()
    Dim Message As Msg
    'loop until bCancel is set to True
    Do While Not bCancel
        'wait for a message
        WaitMessage
        'check if it's a HOTKEY-message
        If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
            'minimize the form
            WindowState = vbMinimized
        End If
        'let the operating system process other events
        DoEvents
    Loop
End Sub
Private Sub Form_Load()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: [email protected]
    Dim ret As Long
    bCancel = False
    'register the Ctrl-F hotkey
    ret = RegisterHotKey(Me.hWnd, &HBFFF&, MOD_CONTROL, vbKeyF)
    'show some information
    Me.AutoRedraw = True
    Me.Print "Press CTRL-F to minimize this form"
    'show the form and
    Show
    'process the Hotkey messages
    ProcessMessages
End Sub
Private Sub Form_Unload(Cancel As Integer)
    bCancel = True
    'unregister hotkey
    Call UnregisterHotKey(Me.hWnd, &HBFFF&)
End Sub

解决方案 »

  1.   

    对于窗体级热键
    有没有其他方法比如我想编一个菜单控件
    怎样为某个菜单项设置热键(该菜单是用API动态创建的)
      

  2.   

    编写钩子函数,使用setwindowshookex进行挂钩,对于窗体级直接通过keypreview
    方法实现,对于进程级可以将钩子函数函数编写进模块中再挂钩实现,对于系统级的热键,需要将钩子函数写入dll中,再进行挂钩实现
      

  3.   

    对于窗体级热键可以使用keypreview的方法实现,对于进程级可以在模块中编写钩子函数,再通过setwindowshookex挂钩实现,对于系统级热键可以将钩子函数写入dll,再通过setwindowshookex全局挂钩实现
      

  4.   

    哦,虽然不能帮你,但是帮你UP一下!希望你能得到好的解答!
    UP! :)
      

  5.   

    怎样为某个菜单项设置热键(该菜单是用API动态创建的)API动态创建的,不是可以随意设置热键吗?
      

  6.   

    To 288794():
    怎么为API动态创建的菜单设置热键?
    我不知道啊!
    假如我是用那种用PictureBox做XP菜单的话,怎么办?
    那时无法接到键盘消息
      

  7.   


    Windows里热键是靠消息循环实现的。除非你更新热键表,否则难以实现,只能自己写代码判断。
    参考API:
    LoadAccelerators, CopyAcceleratorTable, CreateAcceleratorTable, DestroyAcceleratorTable
      

  8.   

    的确的用api,我来UP以下,
    关注!!!1
      

  9.   

    To plainj(狗日的户口_一辈子摸不掉烙印。) :
    因为我的名字读起来有点像910
    而且以拼音首字母分别是zyl
    所以叫zyl910