Results 1 to 3 of 3

Thread: detect when F5 is pressed?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    137

    detect when F5 is pressed?

    When F5 is pressed, i need to run a function, is there a stable way to do this? i remember before i found scripts run in timers with 1ms which didnt work too well.
    Thanks for all your help here!
    I will do my best to add you to the credits of my new apps.

  2. #2
    Hyperactive Member Jimq's Avatar
    Join Date
    Apr 2009
    Posts
    260

    Talking Re: detect when F5 is pressed?

    Hey joey have tried getasyncstate, but for that you have to use timer :-
    Code:
    Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    
    Private Sub Timer1_Timer
    
       If GetAsyncKeyState(vbKeyF8) <> 0 Then
          ' Do something
       End If
    
    End Sub
    set the time inerval to minimum....
    hhope it'll work

  3. #3
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: detect when F5 is pressed?

    I id this in the KeyDown event but it can also be put in the KeyUp event if you wish.

    Code:
    Option Explicit
    
    Private Sub Form_Load()
       Me.KeyPreview = True
    End Sub
    
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
       If KeyCode = 116 Then
          MsgBox "F5 was pressed. Call your function here"
       End If
    End Sub
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

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