我有这个代码:
Public Sub FuncKeysModule(ByVal value As Keys)
'Check what function key is in a pressed state, and then perform the corresponding action.
Select Case value
Case Keys.F8
spam.Enabled = True
TabControl1.SelectedIndex = 0
state = "Activo"
Case Keys.F9
spam.Enabled = False
TabControl1.SelectedIndex = 1
state = "Parado"
End Select
End Sub
Private Sub frmMain_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
If e.KeyValue = Keys.F1 Or Keys.F2 Or Keys.F3 Or Keys.F4 Or Keys.F5 Or Keys.F6 Or Keys.F7 Or Keys.F8 Or Keys.F9 Or Keys.F10 Or Keys.F11 Or Keys.F12 Then
FuncKeysModule(e.KeyValue)
e.Handled = True
End If
End Sub
当我按F8或F9时,Form会调用你可以看到的函数。但我有一个家伙,如果表单是最小化的或未选择的(如果我的TopMost为True),我该怎么称呼它?
谢谢。)
我有这个代码:
http://pastebin.com/Vr8UjVnF
但每次我运行我的项目时,都会出现异常,无法设置键盘挂钩
我能做什么?:S
这是可能的,你必须取消选中项目的Properties->Debug表上的"Enable Visual Studio hosting process",并使用以下代码:
http://pastebin.com/Vr8UjVnF
它的工作原理:)