Saturday, June 02, 2007

Using Function Keys in Visual Basic Forms

Function keys as Shortcut Keys in VB
Function keys are a boon for assigning shortcuts. They have more advantage than the regular Alt + or Ctrl + combination.

Function keys can be assigned to command buttons using simple tricks as explained below. For that we need to instuct the VB to handle them in t
he Keydown event by setting the Keypreview = True

Then you can have the necessary shortcut keys on the form

In the Form_KeyDown event redirect to necessary functions/procs based on the key

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode

Case vbKeyF2

Call Proc_Fund_Transfer

Case vbKeyF3

Call Proc_Credit_Card

End Select

End Sub


  1. Anonymous8:04 AM

    I wanted to use function keys to move through a recordset displayed in a form. ANd the keydown event works with the keypreview property of the form set to true. HOWEVER, I used F10 and F9 as movenext and moveprevious
    and when I look at the keycodes being generated , on of the funciton keys only regristers on EVERY-OTHER keydown event, yet the KEYUP event fires correctly. DOes anyone know why this would be or how to fix it.


  2. Anonymous3:42 PM

    I need to do this but in visual studio 2008, anyone can help me

  3. Check if the following helps you:

  4. This one doesn't work for me. I've tried to use KeyDown event of my form. But the Sub is never called.

  5. Anonymous4:05 AM

    Does work OK for me.


Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.