c# – Processing Russian characters from the wpf keyboard


I wrote a code that processes keystrokes on the keyboard, but if you switch the layout to Russian, the characters are still written in Latin letters, how to make Russian characters read in the same way when switching the layout

 DataTable dt = new DataTable();

    public MainWindow()
        dt.Columns.Add("Key_Code", typeof(string));
        dt.Columns.Add("Key_Value", typeof(string));
        dt.Columns.Add("Key_State", typeof(string));
        dt.Columns.Add("Key_Char", typeof(string));
        dt.Columns.Add("System_Key", typeof(string));
        dt.Columns.Add("Key_Down", typeof(string));
        dt.Columns.Add("Key_Up", typeof(string));

    private void KeyEvents(object sender, KeyEventArgs e)

        if (e.IsRepeat) return;
        string s = "" + e.Key; // key code
        string x = "" + e.SystemKey; // system key
        string z = "" + e.KeyStates; // key state
        string q = "" + e.IsUp; // key up
        string d = "" + e.IsDown; // key down
        string val = "" + (int)e.Key; // key value
        string ch = "" + (char)e.Key;// key char

        dt.Rows.Add(new string[] { s, val, z, ch, x, d, q });

        dg1.ItemsSource = dt.DefaultView;


If you take another event, for example TextInput, then you can intercept the Russian character, but this event has no properties such as keydown and keyup

Scroll to Top