1 に答える
Pressing Ctrl, Alt, or Shift individually caused
Control
,Alt
, andShift
to returntrue
in myKeyDown
event handler. Pressing each one of those keys individually resulted infalse
being returned in myKeyUp
event handler. Are you sure you're not handling theKeyUp
event?As @sean woodward said,
should map to either
Keys.LWin
orKeys.RWin
The
KeyPress
event 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+B
is not a character so you can't useKeyChar
alone to get that information. Try using theKeyDown
orKeyUp
event and looking at theModifiers
property to get a comma delimited string of which modifier keys are being pressed. If order matters you'll need to track that asModifiers
always returns the keys in the same order, i.e.Shift, Control, Alt
even 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);
};