获取关键preSS字符 [英] Get KeyPress character
本文介绍了获取关键preSS字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想在WPF RichtTextbox的pressed字符。
I just want to get the pressed char in WPF RichtTextbox.
Private Sub rtb_KeyDown(sender As Object, e As System.Windows.Input.KeyEventArgs) Handles rtb.KeyDown
Dim KeyConverter As New Forms.KeysConverter
Dim S As String = KeyConverter.ConvertToString(e.Key)
End Sub
但我只有keyDown事件。在KEYDOWN就变得很复杂赶上合适的角色。大写/小写和像SHIFT通过的keydown被解雇特殊键,我首先需要计算到pressed关键。那是复杂的。 因为WPF是在大多数情况下那么复杂,我会问,如果你知道什么办法让键盘上的pressed密钥字符串或字符?
But I only have keyDown event. On Keydown it becomes to be very complicated to catch the right character. Uppercase/Lowercase and special keys like "SHIFT" are fired by keydown, I first need to calculate to the pressed key. Thats complicated. Because WPF is less complicated in most cases, I will ask if you know any way to get the pressed key on keyboard as string or char?
问候
推荐答案
尝试使用 previewTextInput
事件:
public Window7() {
this.InitializeComponent();
this.richTextBox.PreviewTextInput += new TextCompositionEventHandler(this.rtb_PreviewTextInput);
}
private void rtb_PreviewTextInput(object sender, TextCompositionEventArgs e) {
var text = e.Text;
var systemText = e.SystemText;
var controlText = e.ControlText;
var kbm = Keyboard.Modifiers;
}
Private Sub richTextBox_PreviewTextInput(sender As System.Object , e As System.Windows.Input.TextCompositionEventArgs)
Dim text As String = e.Text
Dim controlText As String = e.ControlText
Dim systemText As String = e.SystemText
Dim keybm As ModifierKeys = Keyboard.Modifiers
End Sub
希望帮助
这篇关于获取关键preSS字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文