将String或Char转换为Keys对象 [英] Convert String or Char to Keys object
本文介绍了将String或Char转换为Keys对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我使用以下代码:
for (int i = 0; i < text.Length; i++)
{
char c = text[i];
Keys k = (Keys)(byte)c;
MessageBox.Show(c.ToString() + "|" + k.ToString());
}
我只能对大写字母进行正确的转换.问题是,我还需要能够复制小写字符,并且在它们上出现转换错误.例如,"e"转换为"NumPad5",其中"E"正确转换为"E".我该如何攻击?我将使用输入字符串并为我要开发的宏播放器创建虚拟按键.
解决方案
这似乎是错误的方法.您是否考虑过使用 SendKeys ?>
If I use the following code:
for (int i = 0; i < text.Length; i++)
{
char c = text[i];
Keys k = (Keys)(byte)c;
MessageBox.Show(c.ToString() + "|" + k.ToString());
}
I can get a correct conversion for uppercase letters only. The problem is, I need to be able to replicate lower case characters as well, and I am getting conversion errors on them. For instance, 'e' converts to 'NumPad5', where 'E' converts correctly to 'E'. How do I attack this? I'm going to be taking input strings and creating virtual key presses for a macro player I am trying to develop.
解决方案
That seems like the wrong approach. Have you considered using SendKeys?
这篇关于将String或Char转换为Keys对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文