vb中如何用快捷键调出窗口
展开全部
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
'Keyboards
Const KEY_BACK = &H08
Const KEY_TAB = &H09
Const KEY_RETURN = &H0D
Const KEY_SHIFT = &H10
Const KEY_CTRL = &H11
Const KEY_ALT = &H12
Const KEY_PAUSE = &H13
Const KEY_CAPSLOCK = &H14
Const KEY_ESC = &H1B
Const KEY_PAGEUP = &H21
Const KEY_PAGEDOWN = &H22
Const KEY_END = &H23
Const KEY_HOME = &H24
Const KEY_LEFT = &H25
Const KEY_UP = &H26
Const KEY_RIGHT = &H27
Const KEY_DOWN = &H28
Const KEY_SELECT = &H29
Const KEY_PRINT = &H2A
Const KEY_PRINTSCREEN = &H2C
Const KEY_INSERT = &H2D
Const KEY_DELETE = &H2E
'小键盘的数字
Const KEY_SMALL0 = &H60
Const KEY_SMALL1 = &H61
Const KEY_SMALL2 = &H62
Const KEY_SMALL3 = &H63
Const KEY_SMALL4 = &H64
Const KEY_SMALL5 = &H65
Const KEY_SMALL6 = &H66
Const KEY_SMALL7 = &H67
Const KEY_SMALL8 = &H68
Const KEY_SMALL9 = &H69
Dim IsTrigger As Boolean
Private Sub Form_Load()
GetAsyncKeyState(Asc("快捷键")) '必须分多个KeyState一起
End Sub
新建一个tmrShow的时钟控件
Private Sub tmrShow_Timer()
If GetAsyncKeyState(Asc("快捷键")) <> 0 And IsTrigger = False Then '如果有打不出来的快捷键用KEY_快捷键表示,前面已经定义完成
Me.Visible = Not Me.Visible
IsTrigger = True
ElseIf IsTrigger = True
IsTrigger = False
End If
End Sub
例子:Ctrl+5做快捷键
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
'Keyboards
Const KEY_BACK = &H08
Const KEY_TAB = &H09
Const KEY_RETURN = &H0D
Const KEY_SHIFT = &H10
Const KEY_CTRL = &H11
Const KEY_ALT = &H12
Const KEY_PAUSE = &H13
Const KEY_CAPSLOCK = &H14
Const KEY_ESC = &H1B
Const KEY_PAGEUP = &H21
Const KEY_PAGEDOWN = &H22
Const KEY_END = &H23
Const KEY_HOME = &H24
Const KEY_LEFT = &H25
Const KEY_UP = &H26
Const KEY_RIGHT = &H27
Const KEY_DOWN = &H28
Const KEY_SELECT = &H29
Const KEY_PRINT = &H2A
Const KEY_PRINTSCREEN = &H2C
Const KEY_INSERT = &H2D
Const KEY_DELETE = &H2E
'小键盘的数字
Const KEY_SMALL0 = &H60
Const KEY_SMALL1 = &H61
Const KEY_SMALL2 = &H62
Const KEY_SMALL3 = &H63
Const KEY_SMALL4 = &H64
Const KEY_SMALL5 = &H65
Const KEY_SMALL6 = &H66
Const KEY_SMALL7 = &H67
Const KEY_SMALL8 = &H68
Const KEY_SMALL9 = &H69
Dim IsTrigger As Boolean
Private Sub Form_Load()
GetAsyncKeyState(Asc("5")) And GetAsyncKeyState(KEY_CTRL) '必须分多个KeyState一起
End Sub
新建一个tmrShow的时钟控件
Private Sub tmrShow_Timer()
If GetAsyncKeyState(Asc("5")) <> 0 And GetAsyncKeyState(KEY_CTRL) <> 0 And IsTrigger = False Then '如果有打不出来的快捷键用KEY_快捷键表示,前面已经定义完成
Me.Visible = Not Me.Visible
IsTrigger = True
ElseIf IsTrigger = True
IsTrigger = False
End If
End Sub
'Keyboards
Const KEY_BACK = &H08
Const KEY_TAB = &H09
Const KEY_RETURN = &H0D
Const KEY_SHIFT = &H10
Const KEY_CTRL = &H11
Const KEY_ALT = &H12
Const KEY_PAUSE = &H13
Const KEY_CAPSLOCK = &H14
Const KEY_ESC = &H1B
Const KEY_PAGEUP = &H21
Const KEY_PAGEDOWN = &H22
Const KEY_END = &H23
Const KEY_HOME = &H24
Const KEY_LEFT = &H25
Const KEY_UP = &H26
Const KEY_RIGHT = &H27
Const KEY_DOWN = &H28
Const KEY_SELECT = &H29
Const KEY_PRINT = &H2A
Const KEY_PRINTSCREEN = &H2C
Const KEY_INSERT = &H2D
Const KEY_DELETE = &H2E
'小键盘的数字
Const KEY_SMALL0 = &H60
Const KEY_SMALL1 = &H61
Const KEY_SMALL2 = &H62
Const KEY_SMALL3 = &H63
Const KEY_SMALL4 = &H64
Const KEY_SMALL5 = &H65
Const KEY_SMALL6 = &H66
Const KEY_SMALL7 = &H67
Const KEY_SMALL8 = &H68
Const KEY_SMALL9 = &H69
Dim IsTrigger As Boolean
Private Sub Form_Load()
GetAsyncKeyState(Asc("快捷键")) '必须分多个KeyState一起
End Sub
新建一个tmrShow的时钟控件
Private Sub tmrShow_Timer()
If GetAsyncKeyState(Asc("快捷键")) <> 0 And IsTrigger = False Then '如果有打不出来的快捷键用KEY_快捷键表示,前面已经定义完成
Me.Visible = Not Me.Visible
IsTrigger = True
ElseIf IsTrigger = True
IsTrigger = False
End If
End Sub
例子:Ctrl+5做快捷键
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
'Keyboards
Const KEY_BACK = &H08
Const KEY_TAB = &H09
Const KEY_RETURN = &H0D
Const KEY_SHIFT = &H10
Const KEY_CTRL = &H11
Const KEY_ALT = &H12
Const KEY_PAUSE = &H13
Const KEY_CAPSLOCK = &H14
Const KEY_ESC = &H1B
Const KEY_PAGEUP = &H21
Const KEY_PAGEDOWN = &H22
Const KEY_END = &H23
Const KEY_HOME = &H24
Const KEY_LEFT = &H25
Const KEY_UP = &H26
Const KEY_RIGHT = &H27
Const KEY_DOWN = &H28
Const KEY_SELECT = &H29
Const KEY_PRINT = &H2A
Const KEY_PRINTSCREEN = &H2C
Const KEY_INSERT = &H2D
Const KEY_DELETE = &H2E
'小键盘的数字
Const KEY_SMALL0 = &H60
Const KEY_SMALL1 = &H61
Const KEY_SMALL2 = &H62
Const KEY_SMALL3 = &H63
Const KEY_SMALL4 = &H64
Const KEY_SMALL5 = &H65
Const KEY_SMALL6 = &H66
Const KEY_SMALL7 = &H67
Const KEY_SMALL8 = &H68
Const KEY_SMALL9 = &H69
Dim IsTrigger As Boolean
Private Sub Form_Load()
GetAsyncKeyState(Asc("5")) And GetAsyncKeyState(KEY_CTRL) '必须分多个KeyState一起
End Sub
新建一个tmrShow的时钟控件
Private Sub tmrShow_Timer()
If GetAsyncKeyState(Asc("5")) <> 0 And GetAsyncKeyState(KEY_CTRL) <> 0 And IsTrigger = False Then '如果有打不出来的快捷键用KEY_快捷键表示,前面已经定义完成
Me.Visible = Not Me.Visible
IsTrigger = True
ElseIf IsTrigger = True
IsTrigger = False
End If
End Sub
参考资料: 键盘输入均从魔塔的大键盘脚本做改动
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询