vb.net - 在 VB.NET 中检测非英语按键

标签 vb.net unicode arabic persian

当用户在 VB.Net 文本框中键入内容时,我想检测按键(假设在写入后我无法从文本框中读取文本)。这对于英语来说很容易(通过使用 e.KeyChar 或 Keys.[A, B, C, ...etc])。但是,如果我将 Windows 中的默认键盘从英语更改为另一种语言(例如阿拉伯语或波斯语),仍然会检测到英语字符(尽管正在输入阿拉伯语或波斯语)。

最佳答案

您可以通过创建一个表来将 ASCII 键盘代码映射到您在键盘上看到的波斯语字符来实现此目的。

VB:

'Create a look-up table
Dim Chars(256) As String
Chars(Asc('Q')) = 'ض';
Chars(Asc('W'))= 'ص';
Chars(Asc('E')) = 'ث';
' and so on...

'Now get it
Dim persianChar As String = Chars(e.KeyValue); 'You have your character

C#:

//Create a look-up table
char[] chars = new char[256];
chars['Q'] = 'ض';
chars['W'] = 'ص';
chars['E'] = 'ث';
// and so on...

//Now get it
char persianChar = chars[e.KeyValue]; //You have your character

关于vb.net - 在 VB.NET 中检测非英语按键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8964748/

相关文章:

database - 如何查看带有阿拉伯字符的 Paradox 数据库文件?

javascript - JavaScript 拆分如何处理阿拉伯语和英语数字字符串?

asp.net - VB.Net 中的可选参数

.net - Right$(string, 3) 的含义

python - 如何在 python 字符串中使用 Unicode 字符

python - Unicode 与 Unicode 表示法

android - 带有 Android ICS 的 Galaxy note 1 上未以阿拉伯语显示 EditText 提示

java - java中的破折号分隔符正在改变输出

javascript - 在完全加载之前关闭子 silverlight 窗口会导致父窗口崩溃

vb.net - 在 windows 中生成声音频率 - VB.Net