Greetings,

There is a bug in the method System.Windows.Forms.ToolStrip.ProcessCmdKey
which can cause application-wide shortcuts to stop working. For instance,
we have an application where there is a global shortcut ctrl + k to open
a form. Whenever the toolstrip is active, however, pressing ctrl + k will
instead behave as if you pressed ctrl + tab.

The problem is the following line from System.Windows.Forms.ToolStrip.ProcessCmdKey
(here reconstructed using the .NET Reflector):

if ((!this.IsDropDown && ((keyData & (Keys.Control | Keys.Tab)) == (Keys.Control
| Keys.Tab))) && (!this.TabStop && this.HasKeyboardInput))

In particular, the following part which is supposed to determine if ctrl
+ tab was pressed:

(keyData & (Keys.Control | Keys.Tab)) == (Keys.Control | Keys.Tab))

But this is clearly a bug, since every keycode for which kc & Keys.Tab ==
Keys.Tab (i.e. 8) will satisfy the condition, including k as well as several
other alphabetic characters. The entire line should instead be:

if ((!this.IsDropDown && ((keyData & Keys.Control) == Keys.Control) &&
((keyData & Keys.KeyCode) == Keys.Tab) && (!this.TabStop && this.HasKeyboardInput))

Which would fix the bug. Right now we had to hack around it instead. The
bug has existed at least since .NET 1.1.

Sincerly,
Sune Foldager
Edlund A/

Re: Bug in System.Windows.Forms.ToolStrip.ProcessCmdKey by Marc

Marc
Tue Jun 24 06:58:45 CDT 2008

A fun one ;-p

"connect" is the place to log bugs:
https://connect.microsoft.com/VisualStudio/Feedback

Marc