您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> 编程语言综合 >> 正文

VB 实现简单的热键/快捷键功能

作者:佚名    责任编辑:admin    更新时间:2022-06-22

   代码如下:

  Private Declare Function GetAsyncKeyState Lib "User32" (ByVal Vkey As Long) As Integer

  Private Function MyHotKey(vKeyCode) As Boolean

  MyHotKey = GetAsyncKeyState(vKeyCode) < 0

  End Function

  Private Sub Form_Load()

  Timer1.Interval = 50

  Label1.Caption = "热键是 F1"

  End Sub

  Private Sub Timer1_Timer()

  If MyHotKey(vbKeyF1) Then

  MsgBox "你按下了热键!", , "热键提示"

  End If

  End Sub

  控件:标签1个,时钟控件1个.