vb怎么设置全局热键

来源:百度知道 编辑:UC知道 时间:2024/05/12 17:12:29
如在VB生成的程序界面不被激活的情况下按下相应的热键也能奏效
比如说我新建一个按钮
代码:msgbox"你按下了热键"
要怎么写代码才能在VB生成的程序界面不被激活的情况下按下相应的热键也能奏效

我不知道你想要怎样的效果,应该是下面的效果吧
我弄过的,可以的
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Dim key1 As Integer
Const keycode1 As Integer = 121

Private Sub Form_Load()
key1 = GetKeyState(keycode1)
Timer1.Interval = 10
Timer1.Enabled = True
Me.Visible = False
End Sub

Private Sub Timer1_Timer()
If GetKeyState(keycode1) <> key1 Then
MsgBox "你按下了热键"
key1 = GetKeyState(keycode1)
End If
End Sub
你要按F10的,就会看到效果啦