tags:

views:

533

answers:

1

hello,

in my c#/winforms application i would like to do something like application wide keyboardshortcuts, which should be triggered anywhere, except if the focus is in a control where the user can edit text, like a textbox.

currently i am overwriting this function to do this.

protected override bool ProcessCmdKey(ref Message msg, Keys keyData);

how can i add an exception to this, that it is not triggered when the user is in an editable control?

thanks!

+1  A: 

I see 2 solutions here.

1) in each editable control, handle all keyboard events and in the eventArgs object, set the Handled property to true;

e.Handled = true;

2) before executing the wide keyboard shortcut, look for the control which has the focus, and if it's a TextBox, ignore it. There's probably a method in each Form to tell what Control has the focus.

The second option is cleaner. I don't give code because I don't have Visual Studio open right now, but if you need more specific code you can ask.

PS: here, I did some googling for you: How to Get FOcused Control?

DonkeyMaster
thanks! second version is good!
clamp