-
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.
-
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 ...
-
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!
-
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
-
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
-
 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.
-
 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
-
 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
-
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!
-
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
-
 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
-
By mannuvashishta in forum .NET
Replies: 1
Last Post: 04-06-2007, 12:47 PM
-
By srinivasintouch in forum .NET
Replies: 2
Last Post: 10-09-2006, 05:34 PM
-
By sachinkataria in forum Java
Replies: 0
Last Post: 09-21-2006, 08:19 AM
-
By RossOliver in forum VB Classic
Replies: 4
Last Post: 03-16-2006, 05:23 PM
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks