Results 1 to 11 of 11

Thread: [2008]Keyboard Shortcut Ctrl instead of Alt

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    [2008]Keyboard Shortcut Ctrl instead of Alt

    Hello,

    I am wondering if it is possible to change from the default Alt to Ctrl for keyboard shortcut.

    In the properties I have done the following: &Call. So when I press the Alt key + C the click event will fire. However, is it possible to change to this to the Ctrl key instead?

    Many thanks,

    Steve
    steve

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008]Keyboard Shortcut Ctrl instead of Alt

    No. That's standard Windows functionality.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

  4. #4
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    UK
    Posts
    285

    Re: [2008]Keyboard Shortcut Ctrl instead of Alt

    Here is a solution; its really ugly, and I can foresee all sorts of problems with this, least of which is the fact that the user won't be seeing the accelerator key, unless a lot more coding is done. Also, I think most users would object to having a non-standard user interface. Everyone is used to hitting the Alt key for acceleration; only your app would demand a that the Ctrl key be used instead. I'm pretty sure that would bug the hell out of most people... All that said, here is the code:

    vb.net Code:
    1. Private _suppress As Boolean
    2.     Private Sub Form4_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    3.         If e.KeyCode = (Keys.Menu And Keys.Alt) Then
    4.             _suppress = True
    5.         Else
    6.             _suppress = False
    7.             Button1.PerformClick()
    8.         End If
    9.     End Sub
    10.  
    11.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    12.         If _suppress Then Exit Sub
    13.         'Do something here...
    14.     End Sub
    I've been known to be wrong ...

  5. #5
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    UK
    Posts
    285

    Re: [2008]Keyboard Shortcut Ctrl instead of Alt

    Oh, I've just noticed that I left out some important logic in the KeyDown event; the way I've posted it, Button1_Click will be called on any non-Alt key; it won't even take a combination. Here is the correct code to call the button's click event with the keyboard combination, Ctrl + B:

    vb.net Code:
    1. Private Sub Form4_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    2.         If e.KeyCode = (Keys.Menu And Keys.Alt) Then
    3.             _suppress = True
    4.         ElseIf e.KeyCode = Keys.B AndAlso e.Control Then
    5.             _suppress = False
    6.             Button1.PerformClick()
    7.         End If
    8.     End Sub
    I've been known to be wrong ...

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: [2008]Keyboard Shortcut Ctrl instead of Alt

    Hello BigMeUp,

    I am looking into this. I will get back to you in a few days, to give you the latest results.

    Thanks,
    steve

  7. #7
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: [2008]Keyboard Shortcut Ctrl instead of Alt

    Hi Steve,

    Throughout all the Microsoft products and sample code you see, a standard has been implemented on purpose. The idea is that anyone who uses one Microsoft product, be it Windows or Word, can get used to button positions, icons and shortcut keys, and take many of these gained knowledge experiences across to any new, or new versioned software product running on the Windows Operating System, or indeed any new version of the Operating System itself.

    There are obviously exceptions by companies who either don't like Microsoft and purposely implement confusing/different shortcut keys, or perhaps target their application at multiple Operating Systems. However the generally accepted pattern is to follow these guidelines. Why intentionally go out of your way to confuse the user and not have them pick up your software and run with it out of the box as fast and easily as possible, giving them an experience which they are used to??
    Last edited by alex_read; Jul 30th, 2008 at 04:32 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: [2008]Keyboard Shortcut Ctrl instead of Alt

    Hello,

    Thanks Alex and I would agree with you a 100%. However, it is what was suggested by the client.

    However, I try out the examples and report back to the Client to see if this is real solution. If not I would advice to use the standard microsoft way.

    Thanks,
    steve

  9. #9
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: [2008]Keyboard Shortcut Ctrl instead of Alt

    I think this might be one of those cases where you need to protect the user from their own stupidity, put your foot down and say no with a list to backup the decision & can copy best part of the advice above.

    However if this is to target a different OS, or make the application perform similar to another of their applications in use by their users most of the time, then perhaps this may be a feasilbe request. If so, your best bet would be to look at using the API, and this page http://allapi.mentalis.org/apilist/GetKeyState.shtml, especially the sample provided there.

    The above solution is ok, but if the focus is upon the form - as soon as the user clicks inside of an editable control such as a textbox, or uses the tab key for example to set focus upon a button, then that wouldn't pickup the shortcut key unless you extended the handles clause to incorporate every form control which supports the KeyDown event.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  10. #10
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: [2008]Keyboard Shortcut Ctrl instead of Alt

    Final note: You couldn't use this in conjuction with the & / underlined letter accelerator key combination.

    If you really needed the functionality there, I would suggest not using the underline at all which denotes an Alt+character combination, but instead inserting a bold blue letter for example:
    Click me!

    You could insert an image on your buttons with this text containing a single styled character, as the alternative would be to use more API wrapper calls and this would be even more time consuming and get even more ugly for you.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  11. #11
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    UK
    Posts
    285

    Re: [2008]Keyboard Shortcut Ctrl instead of Alt

    i don't know about you, but i am paid to do what i am told, not to program. there are thosands of programmers who would only be too happy to step into my shoes. if the client is unhappy with your work, he can take his business elsewhere. by all means, tell him why it is not such a good idea to use the control key instead of the alt key, but if he insists, well, that's his problem... take the money and run, that's all

    btw, you don't need to get down and dirty with api's. just set the form's keypreview property to true.
    I've been known to be wrong ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width