给程序指定热键

Option Explicit

     Private Declare Function SendMessage Lib “user32″ Alias “SendMessageA” (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
     Const WM_SETHOTKEY = &H32
     Const HOTKEYF_SHIFT = &H1   ‘ shift键
     Const HOTKEYF_CONTROL = &H2   ‘ctrl键
     Const HOTKEYF_ALT = &H4   ‘alt键
     Const HOTKEYF_EXT = &H8   ‘附加键

     Private Type tInteger
     aint As Integer
     End Type
     Private Type t2Byte
     lByte As Byte
     hByte As Byte
     End Type
     Private ii As tInteger
     Private bb As t2Byte

Private Sub Command1_Click()

End Sub

Private Sub Form_Load()
     Dim wParam As Long, I As Long

     ‘设定ctl-shift-T为该window的hotkey
     bb.hByte = HOTKEYF_CONTROL Or HOTKEYF_SHIFT
     bb.lByte = vbKeyT
     LSet ii = bb

     wParam = CLng(ii.aint)
     I = SendMessage(Me.hWnd, WM_SETHOTKEY, wParam, 0)
     If I = 1 Then
      Debug.Print “Ctl-Shift-T为hotkey”"”
     Else
      If I = 2 Then
      Debug.Print “有其他Window也用Ctl-Shift-T作Hotkey”
      Else
      Debug.Print “指定失败”
      End If
     End If
End Sub

相关日志

Leave a Reply