title: How to get keyboard scancode of pressed Key?
body: <p>I make an WPF app where hotkeys are chosen for their physical position on the keyboard, rather than for what letter they represent.
  Because different users use different layout (qwerty, azerty, etc), my app must be smart enough to be layout-agnostic.</p>
  <p>I designated QWERTY as the layout of reference.</p>
  <p>So for example a French user uses AZERTY. Therefore what the <code>Q</code> key is in QWERTY is <code>A</code> in AZERTY.</p>
  <p>So in order to be agnostic I imagine I should do the following operation:</p>
  <pre class="lang-cs prettyprint-override"><code>// Represents, in QWERTY, the top-left letter key.
  Key myKey = Key.Q; 
  
  // ScanCode represent the physical key on the keyboard.
  var scanCode = GetScanCodeFromKey(myKey, new CultureInfo(&quot;en-US&quot;)); 
  
  // Would be &quot;A&quot; if the user uses AZERTY.
  Key agnosticKey = getKeyFromScanCode(scanCode, CultureInfo.CurrentCulture);
  </code></pre>
  <p>This seems feasible, but I cannot find a function that does <code>GetScanCodeFromKey</code> and <code>getKeyFromScanCode</code>.</p>
  <p>The only relevant post I've found is <a href="https://stackoverflow.com/questions/4822261/is-it-possible-to-create-a-keyboard-layout-that-is-identical-to-the-keyboard-use/4823095#4823095">Is it possible to create a keyboard layout that is identical to the keyboard used?</a>
  but unfortunately it seems to be made for win32, and not WPF. <code>MapVirtualKeyEx</code> is not accessible from WPF.</p>