我想发送NumPad键的击键(1-9).
我试着用:
SendKeys.SendWait("{NUMPAD1}");但上面写着
System.ArgumentException:关键字NUMPAD1无效(翻译)
所以我不知道NumPad的正确密钥。
发布于 2017-07-13 09:55:55
出于好奇,我看了源代码 for SendKeys。没有什么能解释为什么数字密码被排除在外。我不建议将此作为首选选项,但可以使用反射将缺失的代码添加到类中:
FieldInfo info = typeof(SendKeys).GetField("keywords",
BindingFlags.Static | BindingFlags.NonPublic);
Array oldKeys = (Array)info.GetValue(null);
Type elementType = oldKeys.GetType().GetElementType();
Array newKeys = Array.CreateInstance(elementType, oldKeys.Length + 10);
Array.Copy(oldKeys, newKeys, oldKeys.Length);
for (int i = 0; i < 10; i++) {
var newItem = Activator.CreateInstance(elementType, "NUM" + i, (int)Keys.NumPad0 + i);
newKeys.SetValue(newItem, oldKeys.Length + i);
}
info.SetValue(null, newKeys);现在我可以用eg了。SendKeys.Send("{NUM3}")。然而,这似乎并不适用于发送alt代码,所以也许这就是他们忽略它们的原因。
发布于 2017-07-06 15:30:18
您应该能够以与传递字母相同的方式传递数字。例如:
SendKeys.SendWait("{A}"); //sends the letter 'A'
SendKeys.SendWait("{5}"); //sends the number '5'https://stackoverflow.com/questions/44952693
复制相似问题