Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The TextBox KeyDown/KeyPress etc will only be raised for keys that may be accepted as input in to the text box (and associated modifiers). As such, you will not see keys handled such as Print Screen etc. The best option I can think of is not ideal, but you could override the ProcessKeyPreview or some other Form level Message interceptor to get notified of ANY key press. Something like...</p> <pre><code>protected override bool ProcessKeyPreview(ref Message m) { var keyCode = (Keys)Enum.ToObject(typeof (Keys), m.WParam); //Insert some logic return base.ProcessKeyPreview(ref m); } </code></pre> <p>Of course, this method will be invoked whenever the FORM has focus, and a key is pressed, so you would have to filter down by doing some form of check (which again is not ideal)</p> <pre><code>if(ReferenceEquals(ActiveControl, textBoxRegionKeys)) {} </code></pre> <p>Which if your dealing with things like UserControls will be very unreliable. </p> <p>As for formatting in to nice friendly messages, I think you basically you will need your own map of special characters... I am not aware of any Globalized lookup for Keys. I will dig a little and update the answer if I find something.</p> <p><strong>Edit</strong> </p> <p>Did a little digging and couldn't find anything obvious for nice key mappings. I would just create a map of "friendly" key names:</p> <pre><code>private static readonly Dictionary&lt;Keys, String&gt; KeysMap = new Dictionary&lt;Keys, String&gt; { { Keys.D1, "1"}, { Keys.D9, "9"} }; </code></pre> <p>And do something like:</p> <pre><code> String friendlyKeyCode; if (!KeysMap.TryGetValue(keyCode, out friendlyKeyCode)) friendlyKeyCode = keyCode.ToString(); </code></pre> <p>Personally, I find this approach better than a massive switch... but that works too.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload