|
-
Mar 7th, 2001, 12:58 PM
#1
I need to create a log file of how often my help system is used. My log is working from my cmdKey click event. But I need help writing the code to tally how many times the 'F1' key is pressed. Any suggestions???????
-
Mar 7th, 2001, 01:23 PM
#2
In the form(or whatever)'s KeyDown or KeyUp event, use an if statement to catch vbKeyF1, the keycode constant for F1. The call whatever log function you have written, telling it that Help has been acessed.
-
Mar 7th, 2001, 01:30 PM
#3
I tried that on the form ... keydown and key press. neither worked.
-
Mar 7th, 2001, 01:32 PM
#4
Fanatic Member
Just set up a counter. Each time your F1 key is pressed, increase it by one and write a quick file to disk with the number inside.
Code:
Dim F1Presses As Long
Dim FSO As FileSystemObject
Private Sub Form_Load()
Dim FF As Integer
Set FSO = New FileSystemObject
If FSO.FileExists(FSO.BuildPath(App.Path, "F1Presses.Log") Then
FF = FreeFile
Open FSO.BuildPath(App.Path, "F1Presses.Log") For Input As #FF
F1Presses = Val(Input$(LOF(FF), FF))
Close #FF
Else
F1Presses = 0
End If
End Sub
Private Sub cmdKey(Key As String)
If Key="F1" Then
F1Presses = F1Presses + 1
Dim FF As Integer
FF = FreeFile()
Open FSO.BuildPath(App.Path, "F1Presses.Log") For Output As #FF
Print #FF, F1Presses
Close #FF
End If
End Sub
Though I didn't put in the correct KeyPress sub, that should get you started. Hope it helps.
-
Mar 7th, 2001, 01:36 PM
#5
Fanatic Member
Ah, any controls on your form take precedence over the form itself for the KeyDown/Up event. You might have to put the code in all your forms KeyDown/Up events so you can catch it. Putting it in the form will not work.
-
Mar 7th, 2001, 01:48 PM
#6
Thanks alot. I'm trying it right now! *s*
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
|