locked
TextBox's KeyDown and KeyUp not being triggered when input is IME (japanese, chinese, korean) (C#) RRS feed

  • Question

  • Hi All,

    I am facing a very strange behavior, when developing a Windows 8 or 8.1 application using Visual Studio 2012/2013 Preview, using C#.

    To make it simple, I have created a new project with a blank xaml page, and added a TextBox. I have added handlers for the KeyDown, KeyUp, TextChanged events.

    When my input language is alphanumeric, like english, everything works fine: KeyDown is triggered, followed by TextChanged, and finally by KeyUp.

    However, if I change my input language to any IME based, like Korean, Japanese, Chinese, the KeyDown and KeyUp are not triggered (only when I press word separators, like 'space', 'comma').

    Unfortunatelly, I have been unable to find a solution for this issue, that would make KeyDown be triggered. Is this a know bug? Is there a way trigger KeyDown when typing a IME character in the textbox?

    Thanks and regards

    Walter


    To try it for yourself, simply use these .xaml and .xaml.cs codes:

    XAML:

    <Page
        x:Class="App3.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:App3"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <TextBox HorizontalAlignment="Left" Margin="50,50,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="467" KeyDown="TextBox_KeyDown" TextChanged="TextBox_TextChanged" KeyUp="TextBox_KeyUp"/>
    
        </Grid>
    </Page>

    XAML.CS

    namespace App3
    {
        public sealed partial class MainPage : Page
        {
            public MainPage()
            {
                this.InitializeComponent();
            }
    
            private void TextBox_KeyDown(object sender, KeyRoutedEventArgs e)
            {
                Debug.WriteLine("KeyDown. key = '{0}'", e.Key.ToString());
            }
    
            private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
            {
                Debug.WriteLine("TextChanged. text = {0}", (sender as TextBox).Text);
            }
    
            private void TextBox_KeyUp(object sender, KeyRoutedEventArgs e)
            {
                Debug.WriteLine("KeyUp. key = '{0}'", e.Key.ToString());
            }
        }
    }

    Oh, just another weirdness:

    If you start typing many random keys fast, while input is IME, notice that, among the "TextChange" output, you will see some few random "KeyUp" outputs, but with alphanumeric or number values, instead of the IME symbols.



    Wednesday, September 4, 2013 9:50 PM

Answers

  • Hi Walter,

    I remember there is a discussion relate with such topic on Chinese forum before, it is a kind of known issue and the solution is the KeyDown event "ate" by IME, and we cannot trigger it.

    I don't know what you want to do with KeyDown event, if the scenario is told, I'd like to help with a possible solution.

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, September 5, 2013 5:58 AM
    Moderator