title: How do you detect a square bracket in a KeyDown or KeyUp WPF event?
body: <p>I'd like to detect if a keystroke would result in a closing <a href="http://en.wikipedia.org/wiki/Bracket#Square_brackets_.5B_.5D" rel="nofollow noreferrer">square bracket</a> <code>]</code> in a <code>KeyDown</code> event of a WPF <code>Popup</code>:</p>
  <pre class="lang-cs prettyprint-override"><code>private void MyPopup_KeyDown(object sender, KeyEventArgs e)
  {
      if (theKeyStrokeWouldResultIsAClosingSquareBracket)
      {
          // ...
          // do stuff
          // ...
          e.Handled = true;
      }
  }
  </code></pre>
  <p>The solution has to work for any keyboard layout. Notice that key mappings of different layouts usually differ quite a lot. Therefore checking for the right key combination (like <code>Ctrl + Alt + Digit 9</code> on a German <a href="http://en.wikipedia.org/wiki/QWERTZ" rel="nofollow noreferrer">QWERTZ</a> keyboard or simply <code>OemCloseBrackets</code> on a US <a href="http://en.wikipedia.org/wiki/QWERTY" rel="nofollow noreferrer">QUERTY</a> keyboard) is unfortunately no solution.</p>
  <p>How can you accomplish such a detection despite these problems?</p>
  <hr />
  <p><strong>EDIT - Adding some information before starting the bounty:</strong></p>
  <p>I'm currently implementing an IntelliSense-like function in my current project. The IntelliSense stuff is inspired by this: <a href="http://www.codeproject.com/Articles/22803/Intellisense-like-Method-Selection-Pop-up-Window" rel="nofollow noreferrer">http://www.codeproject.com/Articles/22803/Intellisense-like-Method-Selection-Pop-up-Window</a></p>
  <p>The custom syntax allows expressions like <code>[abc].[def] &gt; [ghi].[jkl]</code>, where an user should be able to make the intellisense function autocomplete the text in the brackets. To make the intellisense  function a bit more similar to Visual Studio's (and lots of other IDEs') behavior, I'd like to enable the user to type a closing square bracket in the popup's list box to force an autocomplete.</p>