Link to home
Start Free TrialLog in
Avatar of GivenRandy
GivenRandy

asked on

PageUp / PageDown - Form and Controls

I have some PageUp/PageDown buttons on a form and I also want to activate/call that functionality whenever the PageUp/PageDown key is pressed. This should happen despite which control has focus. How do I do this?
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

Try this:

Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 100
End Sub

Private Sub Timer1_Timer()

If GetAsyncKeyState(vbKeyPageDown) Then
MsgBox "page down was pressed do something here"
ElseIf GetAsyncKeyState(vbKeyPageUp) Then
MsgBox "page up was pressed do something here"
End If

End Sub
Avatar of GivenRandy

ASKER

Using some different search terms, I found something like this:

Private Sub Form_Load()
    Form1.KeyPreview = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyPageDown
            MsgBox "vbKeyPageDown"
        Case vbKeyPageUp
            MsgBox "vbKeyPageUp"
        Case vbKeyDown
            MsgBox "vbKeyDown"
        Case vbKeyUp
            MsgBox "vbKeyUp"
        Case vbKeyHome
            MsgBox "vbKeyHome"
        Case vbKeyEnd
            MsgBox "vbKeyEnd"
        Case vbKeyRight
            MsgBox "vbKeyRight"
        Case vbKeyLeft
            MsgBox "vbKeyLeft"
        Case Else
            MsgBox "Else"
    End Select
End Sub
ASKER CERTIFIED SOLUTION
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial