(using WPF) i try to detect when Ctrl + Enter gets hit. so i tried this code:
if (e.Key == Key.Return && (e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl))
{
//Do Something
}
Obviously this is not correct, as it does not work. Could anyone help me out, explaining what the right way should be ?
thanx
To check whether user pressed ENTER key on webpage or on any input element, you can bind keypress or keydown event to that element or document object itself. Then in bind() function check the keycode of pressed key whether it's value is 13 is not.
To trigger a click button on ENTER key, We can use any of the keyup(), keydown() and keypress() events of jQuery. keyup(): This event occurs when a keyboard key is released. The method either triggers the keyup event, or to run a function when a keyup event occurs.
Definition and Usage The ctrlKey property returns a Boolean value that indicates whether or not the "CTRL" key was pressed when a mouse event was triggered. Note: This property is read-only.
simulatorControl([17,90], function(){console. log('You have pressed Ctrl+Z');}); In the code I have displayed how to perform for Ctrl + Z . You will get Detailed Documentation On the link.
Obviously e.Key
can't be equal to more than one different value in the same event.
You need to handle one of the events that uses KeyEventArgs
, there you'll find properties such as Control
and Modifiers
that will help you detect combinations.
The KeyPress
event, which uses KeyPressEventArgs
, just doesn't have sufficient information.
Drat, you said WPF didn't you. It looks like you need e.KeyboardDevice.Modifiers
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With