|
-
Feb 15th, 2011, 04:34 PM
#1
Thread Starter
Junior Member
NEWBIE ALERT: Event Handling
I have alot of experience in working in VBA for excel, but not so much experience in creating my own structures so it's all still a bit foggy.
I'm trying to capture the event for when the F1 key is pressed, not just when the form is active, but anytime the program is running. The code below expressing the handling is automatically generated for me in VB Express... But I'd like to change the situation to encompass anytime the program is open. I guess I have to reference events that happen in windows in general, but i don't know how to do it. I think i have to create the even in a class module??? If someone could kind of shove me in the right direction, I'd be very much appreciative.
Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = "112" Then
Call SaveWholeForm()
End If
End Sub
-
Feb 15th, 2011, 04:39 PM
#2
Re: NEWBIE ALERT: Event Handling
search the forum for registerhotkey/unregisterhotkey api's to use system wide hotkeys. i wouldn't recommend using the F1 key though. it's used as a help key by windows
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 15th, 2011, 04:44 PM
#3
Re: NEWBIE ALERT: Event Handling
1. You need to set the form.KeyPreview property to True. In form designer, you click on the form to select it and look in the properties window for the KeyPreview property and change it to True (default value is False)
2. Paste in this code
Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.F1 Then
SaveWholeForm()
End If
End Sub
Edit: Never mind... I didn't know that you need a system wide keyboard hook
Last edited by stanav; Feb 15th, 2011 at 04:45 PM.
Reason: Never mind... I didn't know that you need a system wide keyboard hook
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Feb 15th, 2011, 08:36 PM
#4
Re: NEWBIE ALERT: Event Handling
It is a very bad idea to use F1 as a hotkey. That is the standard Windows shortcut for Help, so users might want to open Help in some other app and they get your app doing something else. Use a hotkey that is unlikely to be in use elsewhere and always use at least two modifier keys.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|