Help: Shorcut key for a commandbutton


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 11 of 11

Thread: Help: Shorcut key for a commandbutton

  1. #1
    Join Date
    Jan 2007
    Posts
    15

    Help: Shorcut key for a commandbutton

    Hello Guys,

    I need help in creating a shortcut key for a command button.


    For example:

    When I press f2 it will call the commandbutton click event.

    I'm not refering to the combination key.


    Thanks in advance!
    Last edited by craver06; 02-02-2008 at 07:44 AM.

  2. #2
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    in form_keydown event .. catch the KeyCode .. for example f2 has the KeyCode = 113 (f3 = 114, f4 =115 and so on ...)

    another way: use a menu with shortcutkey ...
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  3. #3
    Join Date
    Jan 2007
    Posts
    15
    thanks for replying!

    Can you give the list of keycode.

    Or do you have a sample program of that?

    If you have, can you share it with me



    Thanks again!

  4. #4
    Join Date
    Jan 2008
    Posts
    73
    Will this help you? Put three Labels on your form.

    Code:
    Option Explicit
    
    
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
       Label1.Caption = ""      ' Clear Label1 on each keydown event
    End Sub
    
    Private Sub Form_KeyPress(KeyAscii As Integer)
       Label1.Caption = "KeyAscii = " & KeyAscii
    End Sub
    
    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
       Label2.Caption = "KeyCode = " & KeyCode
       If Label1.Caption = "" Then
       Label1.Caption = "No Ascii equivalent for this key stroke!"
       End If
    End Sub
    
    Private Sub Form_Load()
      Me.Show
       Label3.Caption = "Press any key to return Ascii Code and KeyCode." & _
       "Then turn CapsLock on and press character keys."
    End Sub

  5. #5
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Code:
    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF2 Then
       Command1.Value = True
    End If
    End Sub
    Make sure the Form's KeyPreview property is set to True or it won't work.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  6. #6
    Join Date
    Jan 2008
    Posts
    73
    Quote Originally Posted by Hack
    Make sure the Form's KeyPreview property is set to True or it won't work.
    Oops! I forgot to mention that when I posted my code.

  7. #7
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Quote Originally Posted by craver06
    Can you give the list of keycode.
    vbKeyF1 through vbKeyF12 cover all of the function keys and you need to use the KeyCode parameter of either KeyUp or KeyDown.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  8. #8
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Quote Originally Posted by craver06
    I'm not refering to the combination key.
    I don't know what you mean by this. What "combination key" are you not referring to?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  9. #9
    Join Date
    Jan 2007
    Posts
    15
    Thanks for replying guyz,

    Is there any an easiest way to put that code in the form other than using

    a menu editor. I'm using a designed fom that has no border, when I put the

    menu editor on it, it will now have a title bar which I don't want to have in

    my form. I have a lot of textboxes in the form and that will have a lot of code

    for that.

    Anyway, Thanks again for the help!


  10. #10
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Just double click on the form and a code window will open up.

    Navigage to the Form's KeyUp event and put the code in.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  11. #11
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Quote Originally Posted by craver06
    Can you give the list of keycode.
    vbKeyLButton Left Mouse Button
    vbKeyRButton Right Mouse Button
    vnKeyCancel Cancel Key
    vbKeyMButton Middle Mouse button
    vbKeyBack Back Space Key
    vbKeyTab Tab Key
    vbKeyClear Clear Key
    vbKeyReturn Enter Key
    vbKeyShift Shift Key
    vbKeyControl Ctrl Key
    vbKeyMenu Menu Key
    vbKeyPause Pause Key
    vbKeyCapital Caps Lock Key
    vbKeyEscape Escape Key
    vbKeySpace Spacebar Key
    vbKeyPageUp Page Up Key
    vbKeyPageDown Page Down Key
    vbKeyEnd End Key
    vbKeyHome Home Key
    vbKeyLeft Left Arrow Key
    vbKeyUp Up Arrow Key
    vbKeyRight Right Arrow Key
    vbKeyDown Down Arrow Key
    vbKeySelect Select Key
    vbKeyPrint Print Screen Key
    vbKeyExecute Execute Key
    vbKeySnapshot Snapshot Key
    vbKeyInsert Insert Key
    vbKeyDelete Delete Key
    vbKeyHelp Help Key
    vbKeyNumlock Delete Key

    vbKeyA through vbKeyZ are the key code constants for the alphabet
    vbKey0 through vbKey9 are the key code constants for numbers
    vbKeyF1 through vbKeyF16 are the key code constants for the function keys
    vbKeyNumpad0 through vbKeyNumpad9 are the key code constants for the numeric key pad

    Math signs are:
    vbKeyMultiply - Multiplication Sign (*)
    vbKeyAdd - Addition Sign (+)
    vbKeySubtract - Minus Sign (-)
    vbKeyDecimal - Decimal Point (.)
    vbKeyDivide - Division sign (/)
    vbKeySeparator - Enter (keypad) sign
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. Replies: 1
    Last Post: 04-06-2007, 12:47 PM
  2. Replies: 2
    Last Post: 10-09-2006, 05:34 PM
  3. Replies: 0
    Last Post: 09-21-2006, 08:19 AM
  4. Replies: 4
    Last Post: 03-16-2006, 05:23 PM
  5. Writing in HKEY_LOCAL_MACHINE...Access is denied
    By Martin in forum VB Classic
    Replies: 22
    Last Post: 12-03-2001, 03:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center