3

I wounder if there is a way to check if a key is clicked?

What I want to achieve is creating something like text editor, I have finished most of the parts. Now when I press on a button, I have a function under element PreviewKeyUp and the other PreviewKeyDown ... Is there something like PreviewKeyClick or KeyClick?

PS: I'm using visual studio 2010 and compiling against .NET Framework 3.5 ... I know I can use 4.0 but 3.5 is due to restrictions on client PC. The application targets a specific client and I can't update the .NET Framework on the client machine. If more details is needed, don't hesitate to ask.

2
  • possible duplicate of Can I enable PreviewClick using InputBindings in WPF? Commented May 11, 2011 at 20:06
  • @Conrad Frix: not a duplicate, the one you`re referring to is for listViews!! not for textBoxes and keyboard button clicks Commented May 11, 2011 at 20:11

2 Answers 2

2

In general, for text editors you would need to handle TextInput (or PreviewTextInput) and KeyDown/PreviewKeyDown events. The latter handles keys not included in TextInput events.

Sign up to request clarification or add additional context in comments.

2 Comments

It worked! Now how can I read the backspace, the spacebar and the return keys in addition to the other keys?
@sikas - I believe you'd need to use KeyDown for things like Backspace/Delete, but general text input should be handled via TextInput. TextInput is smart about various things, like entering non-ASCII characters. Different languages have different rules/input. So typing "ab" in English will be "ab", but in another language it may result in an "a" with an accent/tilde on top.
2

KeyPress event is what you are looking for I think. Warning: It does not work for non-character keys.

4 Comments

I can`t find KeyPress event in the list I see when I press "K" ... I can find KeyUp and KeyDown Only!!
msdn.microsoft.com/en-us/library/… I do not know why you can't see it, but it is there
I guess it is not supported in WPF!
@sikas Correct. In WPF you'd probably want to use KeyDown.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.