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?
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(vbKeyPage
MsgBox "page down was pressed do something here"
ElseIf GetAsyncKeyState(vbKeyPage
MsgBox "page up was pressed do something here"
End If
End Sub