Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect Ctrl + Enter

Tags:

c#

wpf

keystroke

(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

like image 943
Dante1986 Avatar asked Apr 24 '12 06:04

Dante1986


People also ask

How do you detect enter press?

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.

How do you trigger a function on Enter?

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.

What is event ctrlKey?

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.

How do you implement Ctrl Z in Javascript?

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.


1 Answers

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.

like image 63
Ben Voigt Avatar answered Sep 22 '22 15:09

Ben Voigt