Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7412349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:31:35+00:00 2026-05-29T06:31:35+00:00

I am handling the PreviewTextInput event on my window to handle swipes from a

  • 0

I am handling the PreviewTextInput event on my window to handle swipes from a magnetic card reader. I handle the event on the window, so that it does not matter which individual control is focused.

Once the handler determines a swipe has started (a ‘%’ or ‘;’ character is input), it handles all events until the swipe is finished. This system generally works quite nicely, with a few important exceptions:

When a space character (and possibly a \n character) are input from the reader, they are not handled by PreviewTextInput, but are sent directly into whatever control is focused. Oddly enough, the handler does receive \r characters. This causes undesired behavior.

What I want is a way to capture all key events at the window level, and have an opportunity to handle them if I want to. I have tried PreviewKeyDown and found it a bit cumbersome to use, and to get char values from. PreviewTextInput is much nicer because I can simply read the Text property.

Is there a reason PreviewTextInput does not handle certain characters? Is there any comparable method to get all events, including spaces?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:31:36+00:00Added an answer on May 29, 2026 at 6:31 am

    I found some sort of explanation in this WPF forum question:

    Because some IMEs will treat whitespace keystroke as part of the text composition process, that’s why it eats up by Avalon to report correct composited text through TextInput event.

    And some more info from the MSDN documentation of the TextInput event:

    … For keyboard input, WPF first sends the appropriate KeyDown/KeyUp events. If those events are not handled and the key is textual (rather than a control key such as directional arrows or function keys), then a TextInput event is raised. There is not always a simple one-to-one mapping between KeyDown/KeyUp and TextInput events because multiple keystrokes can generate a single character of text input and single keystrokes can generate multi-character strings. This is especially true for languages such as Chinese, Japanese, and Korean which use Input Method Editors (IMEs) to generate the thousands of possible characters in their corresponding alphabets.

    When WPF sends a KeyUp/KeyDown event, Key is set to Key.System if the keystrokes could become part of a TextInput event (if ALT+S is pressed, for example). This allows code in a KeyDown event handler to check for Key.System and, if found, leave processing for the handler of the subsequently raised TextInput event. In these cases, the various properties of the TextCompositionEventArgs argument can be used to determine the original keystrokes. Similarly, if an IME is active, Key has the value of Key.ImeProcessed, and ImeProcessedKey gives the original keystroke or keystrokes.

    BTW, Here are two related questions:

    • How can I prevent input controls from stealing the space character from the TextCompositionManager?
    • Help with the WPF TextCompositionManager events
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Event Handling Guide for iOS mentions the Device Features Programming Guide. However, that
Between handling the Page_Init event or overriding the OnInit method of a Page, which
When handling Control.OnKeyPress event, there is a KeyPressEventArgs that contains a KeyChar . For
ExtJS Class Handling is good to handle, but you have to pay it with
I need to implement handling of redelivery of JMS messages in the application that
How should I be handling, or rather NOT handling (ignoring), touches to my background
In a quest for handling events (like mouse moves and clicks) not by subclassing,
I'm handling an exception in a FaultActivityHandler, at the end of which, I wish
I was handling yet another KeyDown event in a user control when I wondered
Handling integer overflow is a common task, but what's the best way to handle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.