1 に答える
Pressing Ctrl, Alt, or Shift individually caused
Control,Alt, andShiftto returntruein myKeyDownevent handler. Pressing each one of those keys individually resulted infalsebeing returned in myKeyUpevent handler. Are you sure you're not handling theKeyUpevent?As @sean woodward said,
should map to either Keys.LWinorKeys.RWinThe
KeyPressevent is only raised when one of the character keys is pressed and will return the character that results from the pressed key or combination of pressed keys.Ctrl+Shift+Bis not a character so you can't useKeyCharalone to get that information. Try using theKeyDownorKeyUpevent and looking at theModifiersproperty to get a comma delimited string of which modifier keys are being pressed. If order matters you'll need to track that asModifiersalways returns the keys in the same order, i.e.Shift, Control, Alteven if that's not how they were pressed.
Here is the code I used, you can try playing around with it:
KeyDown += (o, ea) =>
{
System.Diagnostics.Debug.WriteLine("KeyDown => CODE: " + ea.KeyCode +
", DATA: " + ea.KeyData +
", VALUE: " + ea.KeyValue +
", MODIFIERS: " + ea.Modifiers +
", CONTROL: " + ea.Control +
", ALT: " + ea.Alt +
", SHIFT: " + ea.Shift);
};
KeyUp += (o, ea) =>
{
System.Diagnostics.Debug.WriteLine("KeyUp => CODE: " + ea.KeyCode +
", DATA: " + ea.KeyData +
", VALUE: " + ea.KeyValue +
", MODIFIERS: " + ea.Modifiers +
", CONTROL: " + ea.Control +
", ALT: " + ea.Alt +
", SHIFT: " + ea.Shift);
};
KeyPress += (o, ea) =>
{
System.Diagnostics.Debug.WriteLine("KeyPress => CHAR: " + ea.KeyChar);
};