dprundle
asked on
Vb.net Hot Key Buttons
In vb.net I need to create hot keys for my buttons. More specifically i need CTRL+F1 through CTRL + F12 to have functions. is this possible and if so how?
ASKER
only when my app is focused.
(assuming WinForms here)
Sorry...one more question...what version VB.Net?
VB.Net 2005?
VB.Net 2003 (or below)?
Sorry...one more question...what version VB.Net?
VB.Net 2005?
VB.Net 2003 (or below)?
ASKER
visual studio 2005 vb.net
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Where do I put this at?
You put this code INSIDE whatever form you want it on:
Private Const WM_KEYDOWN As Integer = &H100
Protected Overrides Function ProcessKeyPreview(ByRef m As System.Windows.Forms.Messa ge) As Boolean
Select Case m.Msg
Case WM_KEYDOWN
If My.Computer.Keyboard.CtrlK eyDown AndAlso (Not My.Computer.Keyboard.AltKe yDown) Then
Select Case m.WParam.ToInt32
Case Keys.F1
Debug.Print("Ctrl F1")
Return True
Case Keys.F2
Debug.Print("Ctrl F2")
Return True
Case Keys.F3
Debug.Print("Ctrl F3")
Return True
' etc...
End Select
End If
End Select
End Function
So it goes INBETWEEN these two lines in the IDE:
Public Class Form1
End Class
Where "Form1" is the name of your form...
Private Const WM_KEYDOWN As Integer = &H100
Protected Overrides Function ProcessKeyPreview(ByRef m As System.Windows.Forms.Messa
Select Case m.Msg
Case WM_KEYDOWN
If My.Computer.Keyboard.CtrlK
Select Case m.WParam.ToInt32
Case Keys.F1
Debug.Print("Ctrl F1")
Return True
Case Keys.F2
Debug.Print("Ctrl F2")
Return True
Case Keys.F3
Debug.Print("Ctrl F3")
Return True
' etc...
End Select
End If
End Select
End Function
So it goes INBETWEEN these two lines in the IDE:
Public Class Form1
End Class
Where "Form1" is the name of your form...
ASKER
Thanks, I was just wondering if I had to do anything special (like create a new class) to get it to work. I'll try it out now.
ASKER
this isn't working.. i even replaced debug.print with msgbox("Im working") and its not doing anything.
ASKER
wow i'm an idiot. i didn't have flock on. Thanks for your help.
"flock"?...
Glad you got it working. =)
Glad you got it working. =)
Do you need these to function ONLY when your app is in FOCUS?
...or at anytime, such as when OTHER apps are active?