如上。

解决方案 »

  1.   

    用全局键盘钩子,看下面的例子:
    (checkbox:chkInterceptKeys用来控制是否拦截住不发送):
    模块中代码:
    Option Explicit' Type Declarations
    Private Type KBDLLHOOKSTRUCT
     vkCode As Long
     scanCode As Long
     Flags As Long
     time As Long
     dwExtraInfo As Long
    End Type' Win32 API
    Private Declare Function SetWindowsHookEx Lib "user32" _
     Alias "SetWindowsHookExA" _
      (ByVal idHook As Long, _
       ByVal lpfn As Long, _
       ByVal hmod As Long, _
       ByVal dwThreadId As Long) As Long
      
    Private Declare Function UnhookWindowsHookEx Lib "user32" _
     (ByVal hHook As Long) As Long
     
    Private Declare Function CallNextHookEx Lib "user32" _
     (ByVal hHook As Long, _
      ByVal nCode As Long, _
      ByVal wParam As Long, _
      ByVal lParam As Long) As Long
      
    Private Declare Sub CopyMemory Lib "kernel32" _
     Alias "RtlMoveMemory" _
      (pDest As Any, _
       pSource As Any, _
       ByVal cbLength As Long)
     
    ' Constants
    Private Const WH_KEYBOARD_LL = 13&      ' Hook Flag
    Private Const HC_ACTION = 0&            ' Keyboard Process Message
     
    ' Variables
    Private m_hLLKeyboardHook As Long       ' The hook object
    Public g_bInterceptKeys As Boolean      ' FlagPublic Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, _
                                         ByVal lParam As Long) As Long
     
     ' Set up the hook object
     Static tKeyboardHook As KBDLLHOOKSTRUCT
     If nCode = HC_ACTION Then
      Call CopyMemory(tKeyboardHook, ByVal lParam, Len(tKeyboardHook))  ' Display some info on the form
      With frmDemo
       .lblvkCode2.Caption = tKeyboardHook.vkCode
       .lblscanCode2.Caption = tKeyboardHook.scanCode
       .lblFlags2.Caption = tKeyboardHook.Flags
       .lblTime2.Caption = tKeyboardHook.time
       .lblExtraInfo2.Caption = tKeyboardHook.dwExtraInfo
       .lblwParam2.Caption = wParam
       .lbllParam2.Caption = lParam
      End With
      
      If g_bInterceptKeys Then
       ' Intercept the key and don't pass it along the hook chain
       LowLevelKeyboardProc = 1
       Exit Function
      End If
      
     End If ' If the message is not one we want to trap, pass it along
     ' through the hook chain to the intended app
     LowLevelKeyboardProc = CallNextHookEx(m_hLLKeyboardHook, nCode, wParam, lParam)End FunctionPublic Function SetSystemWideKeyboardHook() As Long ' Hook into the keyboard process
     
     ' Specifying 0 for the last parameter (dwThreadId) indicates a system wide
     ' hook
     
     If m_hLLKeyboardHook = 0 Then
      m_hLLKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0&)
     End If If m_hLLKeyboardHook = 0 Then
      SetSystemWideKeyboardHook = 0
     Else
      SetSystemWideKeyboardHook = 1
     End IfEnd FunctionPublic Function UnSetSystemWideKeyboardHook() As Long ' Unhook from the keyboard process
     
     If m_hLLKeyboardHook <> 0 Then
      Call UnhookWindowsHookEx(m_hLLKeyboardHook)
      m_hLLKeyboardHook = 0
      UnSetSystemWideKeyboardHook = 1
     Else
      UnSetSystemWideKeyboardHook = 0
     End IfEnd Function
    窗体代码:
    Option ExplicitPrivate Sub Form_Load() ' Set up the form
     
     Me.Caption = "System Wide Keyboard Hook"
     
     '  I left the labels with borders in design time so they can be seen on the
     '  form. This simply removes the border
     lblvkCode1.BorderStyle = 0
     lblvkCode2.BorderStyle = 0
     lblscanCode1.BorderStyle = 0
     lblscanCode2.BorderStyle = 0
     lblFlags1.BorderStyle = 0
     lblFlags2.BorderStyle = 0
     lblTime1.BorderStyle = 0
     lblTime2.BorderStyle = 0
     lblExtraInfo1.BorderStyle = 0
     lblExtraInfo2.BorderStyle = 0
     lblwParam1.BorderStyle = 0
     lblwParam2.BorderStyle = 0
     lbllParam1.BorderStyle = 0
     lbllParam2.BorderStyle = 0
     
     With chkInterceptKeys
      .Caption = "Intercept keys (test it in Notepad)"
      .Enabled = False
     End With
     
     fmeKeyInfo.Caption = "Keyboard Hook Info [Not Hooked]"
     
    End SubPrivate Sub chkInterceptKeys_Click()
     ' Set the global flag to see if we should
     ' absorb the right click messages
     g_bInterceptKeys = chkInterceptKeys.Value = 1
    End SubPrivate Sub cmdSet_Click()
     ' Attempt to set the hook
     If SetSystemWideKeyboardHook = 1 Then
      fmeKeyInfo.Caption = "Keyboard Hook Info [Hooked]"
      chkInterceptKeys.Enabled = True
     Else
      fmeKeyInfo.Caption = "Keyboard Hook Info [Unable to Hook]"
     End If
    End SubPrivate Sub cmdUnSet_Click()
     If UnSetSystemWideKeyboardHook = 1 Then
      fmeKeyInfo.Caption = "Keyboard Hook Info [UnHooked]"
      lblvkCode2.Caption = ""
      lblscanCode2.Caption = ""
      lblFlags2.Caption = ""
      lblTime2.Caption = ""
      lblExtraInfo2.Caption = ""
      lblwParam2.Caption = ""
      lbllParam2.Caption = ""
      
      With chkInterceptKeys
       .Value = 0
       .Enabled = False
      End With Else
      fmeKeyInfo.Caption = "Keyboard Hook Info [Hook Not Set]"
     End If
    End SubPrivate Sub Form_Unload(Cancel As Integer)
     Call UnSetSystemWideKeyboardHook
    End Sub
      

  2.   

    其实很简单的
    一个是
    if command1.click'点击了确定按钮
    ....
    end if
    还有个就是在窗体的keypress事件中
    If KeyAscii = 13 Then'接收按的回车键
    ......
    End If
    End Sub
      

  3.   

    界面
    lblvkCode1.BorderStyle = 0
     lblvkCode2.BorderStyle = 0
     lblscanCode1.BorderStyle = 0
     lblscanCode2.BorderStyle = 0
     lblFlags1.BorderStyle = 0
     lblFlags2.BorderStyle = 0
     lblTime1.BorderStyle = 0
     lblTime2.BorderStyle = 0
     lblExtraInfo1.BorderStyle = 0
     lblExtraInfo2.BorderStyle = 0
     lblwParam1.BorderStyle = 0
     lblwParam2.BorderStyle = 0
     lbllParam1.BorderStyle = 0
     lbllParam2.BorderStyle = 0
    都是label
    fmeKeyInfo是frame
    chkInterceptKeys是checkbox
    cmdSet
    cmdUnSet
    是按钮chkInterceptKeys的作用是选择是否拦截住
      

  4.   

    是否为全局的hook看SetWindowsHookEx的参数说明关于dwThreadIddwThreadId
    [in] Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread. 如果最后这个参数为0,那么就是全局的hook
      

  5.   

    钩子毕竟危险,但是准确无误,一般情况下可以用
    Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer
      

  6.   

    看看这个
    http://202.102.230.151/hookdll.rar