Results 1 to 6 of 6

Thread: Function Keys

  1. #1
    karzz
    Guest

    Question

    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???????

  2. #2
    Guest
    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.

  3. #3
    Guest
    I tried that on the form ... keydown and key press. neither worked.

  4. #4
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    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.
    -Excalibur

  5. #5
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    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.
    -Excalibur

  6. #6
    Guest
    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
  •  



Click Here to Expand Forum to Full Width