For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > August 2005 > Shortcut Key!









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Shortcut Key!
Arpan

2005-08-27, 6:55 pm

I have a VB6 Form where I want that when the user presses the 'Esc' key
on the keyboard, the textbox in the Form should become blank but the
Menu Editor doesn't list 'Esc' in the Shortcut drop-down list. Isn't
there any way by which the 'Esc' key can be made a shortcut key?

Thanks,

Arpan

Mike L

2005-08-27, 9:56 pm

"Arpan" <arpan_de@hotmail.com> wrote:
> I have a VB6 Form where I want that when the user presses the 'Esc' key
> on the keyboard, the textbox in the Form should become blank but the
> Menu Editor doesn't list 'Esc' in the Shortcut drop-down list. Isn't
> there any way by which the 'Esc' key can be made a shortcut key?


You could insert this code into the KeyDown event of your controls:

'========
Select Case KeyCode
Case vbKeyEscape
'put your code here
End Select
'========

but, (I'm not positive about this, so someone please correct me if I'm
wrong) you have to include the above code in the KeyDown event on each
control on your form, and the form itself.


Ted

2005-08-27, 9:56 pm

Set the form KeyPreview property to True

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then Text1.Text = ""
End Sub



"Arpan" <arpan_de@hotmail.com> wrote in message
news:1125186670.618830.53970@g14g2000cwa.googlegroups.com...
>I have a VB6 Form where I want that when the user presses the 'Esc' key
> on the keyboard, the textbox in the Form should become blank but the
> Menu Editor doesn't list 'Esc' in the Shortcut drop-down list. Isn't
> there any way by which the 'Esc' key can be made a shortcut key?
>
> Thanks,
>
> Arpan
>



Arpan

2005-08-27, 9:57 pm

Thanks, Mike & Ted, for your inputs. Actually the Form has a menu where
one of the menu items is 'Clear'. Corresponding to this 'Clear' menu
item, I want the shortcut key to be displayed as 'Esc' similar to, say,
the Paste menu item under the Edit menu in most Windows applications
corresponding to which Ctrl+V is displayed so that the user knows the
Ctrl+V is the shortcut key for pasting. I am not able to do this since
the Menu Editor doesn't list 'Esc' as a shortcut key in the Shortcut
drop-down list. In other words, I want the user to know that the 'Esc'
key is a shortcut key for clearing the textbox & that when he presses
the 'Esc' key, the textbox will be cleared.

I hope I have made things clearer!

Thanks once again,

Regards,

Arpan

Ted

2005-08-27, 9:57 pm

Unfortunately you can do that by placing the Esc after the menu title
with a bunch of spaces in between.
example:
Clear Esc





"Arpan" <arpan_de@hotmail.com> wrote in message
news:1125190155.213659.233980@z14g2000cwz.googlegroups.com...
> Thanks, Mike & Ted, for your inputs. Actually the Form has a menu where
> one of the menu items is 'Clear'. Corresponding to this 'Clear' menu
> item, I want the shortcut key to be displayed as 'Esc' similar to, say,
> the Paste menu item under the Edit menu in most Windows applications
> corresponding to which Ctrl+V is displayed so that the user knows the
> Ctrl+V is the shortcut key for pasting. I am not able to do this since
> the Menu Editor doesn't list 'Esc' as a shortcut key in the Shortcut
> drop-down list. In other words, I want the user to know that the 'Esc'
> key is a shortcut key for clearing the textbox & that when he presses
> the 'Esc' key, the textbox will be cleared.
>
> I hope I have made things clearer!
>
> Thanks once again,
>
> Regards,
>
> Arpan
>



MikeD

2005-08-27, 9:57 pm


"Arpan" <arpan_de@hotmail.com> wrote in message
news:1125190155.213659.233980@z14g2000cwz.googlegroups.com...
> Thanks, Mike & Ted, for your inputs. Actually the Form has a menu where
> one of the menu items is 'Clear'. Corresponding to this 'Clear' menu
> item, I want the shortcut key to be displayed as 'Esc' similar to, say,
> the Paste menu item under the Edit menu in most Windows applications
> corresponding to which Ctrl+V is displayed so that the user knows the
> Ctrl+V is the shortcut key for pasting. I am not able to do this since
> the Menu Editor doesn't list 'Esc' as a shortcut key in the Shortcut
> drop-down list. In other words, I want the user to know that the 'Esc'
> key is a shortcut key for clearing the textbox & that when he presses
> the 'Esc' key, the textbox will be cleared.


That's a very unconventional use of the Esc key. Esc is usually used to
cancel an action or to close a window (for example, a dialog box). I can't
recall ever seeing Esc used to clear a textbox (or clear anything else, for
that matter). It's important to follow established standards and
conventions. If you don't, your program will be more difficult to learn and
use. This is just my opinion, but I would think using Esc as you're wanting
would just confuse and frustrate users.

I would recommend something like Alt+C for your Clear menu command. Of
course, this would preclude you from having a menubar command that uses "C"
as its accelerator keystroke to drop down that menu, so you might want to
use something else. I definately would not recommend Ctrl+C because that's
pretty much a de facto standard for Copy.

Another option would be a 'Select All' menu command (preferably in your Edit
menu) with a shortcut key of Ctrl+A, which is a fairly standard menu command
and keystroke. The user can just press Ctrl+A and then Delete. It's only
one more keystroke and users are likely already accustomed to this keystroke
sequence for "clearing".

Either of these would be much more conventional than using Esc to clear the
textbox.

--
Mike
Microsoft MVP Visual Basic


Tom Esh

2005-08-27, 9:57 pm

On 27 Aug 2005 16:51:10 -0700, "Arpan" <arpan_de@hotmail.com> wrote:

>I have a VB6 Form where I want that when the user presses the 'Esc' key
>on the keyboard, the textbox in the Form should become blank but the
>Menu Editor doesn't list 'Esc' in the Shortcut drop-down list. Isn't
>there any way by which the 'Esc' key can be made a shortcut key?



A Tab char actually provides the correct alignment, but you have to do
it at runtime:
mnuClear.Caption = "Clear" & vbTab & "Esc"

Also if, as others suggested, you use one of the form's Key events to
grab it, be sure there is no command button on the form with its
"Cancel" property set True as it will hijack the Esc key regardless of
the KeyPreview setting. That brings up the issue of standard UI
behavior as MikeD noted. Sometimes it makes sense to change it but
usually when you find yourself working around those behaviors you're
better off reconsidering. :-)

-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
Larry Serflaten

2005-08-27, 9:57 pm


"Arpan" <arpan_de@hotmail.com> wrote
> Thanks, Mike & Ted, for your inputs. Actually the Form has a menu where
> one of the menu items is 'Clear'. Corresponding to this 'Clear' menu
> item, I want the shortcut key to be displayed as 'Esc' similar to, say,
> the Paste menu item under the Edit menu in most Windows applications
> corresponding to which Ctrl+V is displayed so that the user knows the
> Ctrl+V is the shortcut key for pasting. I am not able to do this since
> the Menu Editor doesn't list 'Esc' as a shortcut key in the Shortcut
> drop-down list. In other words, I want the user to know that the 'Esc'
> key is a shortcut key for clearing the textbox & that when he presses
> the 'Esc' key, the textbox will be cleared.
>


You can add the "Esc" part to the menu item's Caption in the form's
Load event. Something like:

mnuClear.Caption = "Clear" & vbTab & "Esc"

or perhaps:

mnuClear.Caption = "&Clear" & vbTab & "Esc"

Where the & provides the underscore like so many menus have....

LFS
Arpan

2005-08-28, 3:55 am

Thanks to one & all for putting forth your suggestions & helping a
newbie.

Mike, in a way, I want my application to cancel an action when the
'Esc' key is pressed. I introduced the textbox in my query just for
brevity.

Actually my application is something like a calculator. So for e.g. if
a user enters 2+3 but then decides to abort this operation, pressing
the 'Esc' key would cancel his action. For such actions, I intend to
make use of the 'Esc' key.

Thanks once again to all of you,

Regards,

Arpan

Kevin Provance

2005-08-28, 3:55 am

Well, for certain, make sure none of your buttons have the property "Cancel"
enabled, otherwise pressing the ESC key will activate the button with the
canceled property that is set to true.

- Kev


"Arpan" <arpan_de@hotmail.com> wrote in message
news:1125204535.177853.98620@g49g2000cwa.googlegroups.com...
> Thanks to one & all for putting forth your suggestions & helping a
> newbie.
>
> Mike, in a way, I want my application to cancel an action when the
> 'Esc' key is pressed. I introduced the textbox in my query just for
> brevity.
>
> Actually my application is something like a calculator. So for e.g. if
> a user enters 2+3 but then decides to abort this operation, pressing
> the 'Esc' key would cancel his action. For such actions, I intend to
> make use of the 'Esc' key.
>
> Thanks once again to all of you,
>
> Regards,
>
> Arpan
>



Michael Cole

2005-08-28, 7:55 am

Arpan wrote:
> Thanks to one & all for putting forth your suggestions & helping a
> newbie.
>
> Mike, in a way, I want my application to cancel an action when the
> 'Esc' key is pressed. I introduced the textbox in my query just for
> brevity.
>
> Actually my application is something like a calculator. So for e.g. if
> a user enters 2+3 but then decides to abort this operation, pressing
> the 'Esc' key would cancel his action. For such actions, I intend to
> make use of the 'Esc' key.


If it like a calculator, then you should have a command button somewhere
labelled "C" for clear. Simply set the Cancel property of that command
button to True. Then put your clearing code in the button's Click event.

See the Windows calculator to see how it works.


--
Regards,

Michael Cole


Jeff Johnson [MVP: VB]

2005-08-29, 3:55 am


"Ted" <2000@xxxmsn.com> wrote in message
news:O1Euau2qFHA.3604@tk2msftngp13.phx.gbl...

> Unfortunately you can do that by placing the Esc after the menu title
> with a bunch of spaces in between.
> example:
> Clear Esc


Spaces? Bad, bad, bad. Inserting a Tab is the way to go.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com