|
-
Jul 24th, 2008, 02:49 AM
#1
Thread Starter
Frenzied Member
[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
-
Jul 24th, 2008, 04:45 AM
#2
Re: [2008]Keyboard Shortcut Ctrl instead of Alt
No. That's standard Windows functionality.
-
Jul 24th, 2008, 05:03 AM
#3
Re: [2008]Keyboard Shortcut Ctrl instead of Alt
Trap the keys yourself and do whatever is required.
-
Jul 24th, 2008, 06:11 AM
#4
Hyperactive Member
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:
Private _suppress As Boolean
Private Sub Form4_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = (Keys.Menu And Keys.Alt) Then
_suppress = True
Else
_suppress = False
Button1.PerformClick()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If _suppress Then Exit Sub
'Do something here...
End Sub
I've been known to be wrong  ...
-
Jul 24th, 2008, 06:24 AM
#5
Hyperactive Member
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:
Private Sub Form4_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = (Keys.Menu And Keys.Alt) Then
_suppress = True
ElseIf e.KeyCode = Keys.B AndAlso e.Control Then
_suppress = False
Button1.PerformClick()
End If
End Sub
I've been known to be wrong  ...
-
Jul 28th, 2008, 05:27 AM
#6
Thread Starter
Frenzied Member
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,
-
Jul 28th, 2008, 07:27 AM
#7
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.
-
Jul 30th, 2008, 04:00 AM
#8
Thread Starter
Frenzied Member
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,
-
Jul 30th, 2008, 04:23 AM
#9
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.
-
Jul 30th, 2008, 04:29 AM
#10
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.
-
Jul 30th, 2008, 03:25 PM
#11
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|