• Advertisement
Sign in to follow this  

[.net] how to disable the default shortcut keys?

This topic is 4707 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi guys, i want to impart the key 'Alt' some specific function, but every time it was pressed the menu would be actived automatically, cause it is the default shortcut key for accessing the menu. so is there any way that i can disable the default shortcut? thank you! sorry for my poor english.

Share this post


Link to post
Share on other sites
Advertisement
Check this out.

You'll have to use PInvoke in .NET to call these functions...

Cheers

Share this post


Link to post
Share on other sites
hey there, i think the "check this out" is great, but it's in c++. i just can't get it. and what's PInvoke?

many thanks!

Share this post


Link to post
Share on other sites
PInvoke is a way of referencing 'ordinary' dll's and invoking their methods.
PInvoke article
For exellent help with PInvoke see this
It has a great plugin for VS and a lot of help.
For the method SetWindodsHookEx see this

Cheers

Share this post


Link to post
Share on other sites
You don't need to call anything externally. Just override ProcessCmdKey from the form.

I have something where I want Alt + mouse button to do something without focusing the menu bar, but at the same time I wanted to be able to hit "Alt-F" to jump to "File" in the menu. So what I did was strip the Alt and Menu modifier from the keyData unless a letter was pressed too. KeyDown, KeyUp, KeyPress will work as normal.

protected override bool ProcessCmdKey(ref Message msg,Keys keyData)
{
//This is a bit ugly for stripping out the modifiers but it works.
int num=((int)keyData)&0xFF;
if(num<(int)Keys.A || num>(int)Keys.Z)
{keyData=keyData&(~Keys.Menu)&(~Keys.Alt);}

return base.ProcessCmdKey(ref msg,keyData);
}

Share this post


Link to post
Share on other sites
This doesn't allow you to disable the windowskey...

Cheers

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement