Page 1 of 1
How to add shortcut keys in Visual Basic Example, I wanted the compute button's shortcut on keyboard as F4
#4
Re: How to add shortcut keys in Visual Basic
Posted 29 September 2008 - 06:08 PM
Hi does anyone here knows the code on how to put shorcut keys?
For example:
I have my program, it has 3 buttons, Compute, Clear, and Exit.
Just in the case that there is no mouse, the user could press keys on the keyboard instead of pointing the mouse into the button then click.
Just like this, Compute - > F4
Clear - > F5
Exit - > F6
How will I assign those keys to link them with the buttons?
Can you give an example sourcecode for it?
Thanks!
For example:
I have my program, it has 3 buttons, Compute, Clear, and Exit.
Just in the case that there is no mouse, the user could press keys on the keyboard instead of pointing the mouse into the button then click.
Just like this, Compute - > F4
Clear - > F5
Exit - > F6
How will I assign those keys to link them with the buttons?
Can you give an example sourcecode for it?
Thanks!
#5
Re: How to add shortcut keys in Visual Basic
Posted 29 September 2008 - 06:13 PM
there is no special property for this
if Vb6
use & char in your caption
for example &Compute will display like this Compute
this means ALT+C will invoke the button click
'sorry i make mistake here its not property its event
if you still want the function keys use forms keydown Event
there
place the code
if keycode = vbkeyf4 then
cmdcompute_click()
End if
one small thing this code will not execute if you not set form's keypreview property to true
if Vb6
use & char in your caption
for example &Compute will display like this Compute
this means ALT+C will invoke the button click
'sorry i make mistake here its not property its event
if you still want the function keys use forms keydown Event
there
place the code
if keycode = vbkeyf4 then
cmdcompute_click()
End if
one small thing this code will not execute if you not set form's keypreview property to true
This post has been edited by thava: 29 September 2008 - 08:54 PM
#7
Re: How to add shortcut keys in Visual Basic
Posted 03 October 2008 - 06:21 AM
Another way to do this would be to tie the events to the OnKey or KeyPress event. This would obviate the need to add extra features like a menu or what not. Just have the events run like this
Sub Form_KeyPress(KeyAscii As Integer) 'Can substitue form with any other control that supports this event If keycode = vbkeyf4 then Compute 'add your computing subroutine here Elseif KeyCode = vbkeyf5 then Clear 'add your clearing subroutine here Elseif KeyCode = vbkeyf6 then Exit 'add your exit subroutine here end if
#8
Re: How to add shortcut keys in Visual Basic
Posted 03 October 2008 - 06:55 AM
@dave, ur code seems to have some mistakes. U r using the keypress event. It only returns the keyascii. And u r using keycode in ur code. Ur code has to b inside the keydown event like thava had told us in the earlier post.
#9
Re: How to add shortcut keys in Visual Basic
Posted 03 October 2008 - 07:06 AM
My mistake. You'll want to use this code then:
Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) 'Can substitue form with any other control that supports this event If KeyCode = 115 then '115 is the numeric KeyCode for F4 Compute 'add your computing subroutine here Elseif KeyCode = 116 then '116 is the numeric KeyCode for F5 Clear 'add your clearing subroutine here Elseif KeyCode = 117 then '117 is the numeric KeyCode for F6 Exit 'add your exit subroutine here end if
Page 1 of 1

Ask A New Question
Reply



MultiQuote






|