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???????
Printable View
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???????
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.
I tried that on the form ... keydown and key press. neither worked.
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.
Though I didn't put in the correct KeyPress sub, that should get you started. Hope it helps.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
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.
Thanks alot. I'm trying it right now! *s*