2011-08-07 39 views
3

我試圖在wpf文本框控件中使用事件keyDown事件,並捕獲帶有e.Key的點擊鍵,但由於「@」字符沒有鍵,我無法抓住它。如何檢測單擊的「@」鍵如何捕捉來自鍵盤的「@」字符輸入

private void richTextBox1_KeyDown(object sender, KeyEventArgs e) 
{ 
    if(e.Key == Key.) // nothing corresponding the at key 
} 
+0

查找char代碼。 – tjameson

回答

3

KeyDown是用於實際的鍵,它不關心他們的解釋。例如,使用PreviewTextInput

private void RichTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e) 
{ 
    if (e.Text == "@") 
    { 
     //... 
    } 
} 
0

Keydown事件使用鍵盤按鈕。它並不知道任何關於角色的事情。

請嘗試使用KeyPress事件。相反,這個事件返回剛剛按下的鍵的ASCII字符碼。

private void Form1_KeyPress(object sender, KeyPressEventArgs e) 
{ 
    if (e.KeyChar == '@') MessageBox.Show("The At sign was pressed"); 
} 

注意:非ASCII字符不會觸發此事件。

+0

這是WPF,不存在這樣的事件。 –

+0

這是wpf,這個事件不存在 – user882611