WatiN 因错误的 keyCode 触发 KeyDown 事件
如果您查看 WatiN.Core.Element.cs 中的代码,您会看到以下内容:
private static NameValueCollection GetKeyCodeEventProperty(char character)
{
return new NameValueCollection
{
{"keyCode", ((int) character).ToString()},
{"charCode", ((int) character).ToString()}
};
}
这是用于模拟客户端事件触发的代码,例如在文本字段中自动输入文本时。在我看来,这段代码生成了错误的 keyCodes。
假设我在文本框中输入字母“v”。 (int)'v' 返回 118。118 是 F7 的 keyCode,而不是“v”的 keyCode,即 86。
果然,我的应用程序检测到 F7 已被按下。
这似乎是完全错误的。我是否在这里遗漏了一些东西 - 我不敢相信如果我没有的话,其他人不会看到这个问题。
预先感谢,
朱利安。
If you look at the code in WatiN.Core.Element.cs you see the following:
private static NameValueCollection GetKeyCodeEventProperty(char character)
{
return new NameValueCollection
{
{"keyCode", ((int) character).ToString()},
{"charCode", ((int) character).ToString()}
};
}
This is the code used to simulate the firing of client side events, for example when automating typing text into a text field. It seems to me that this code generates the wrong keyCodes.
Let's say that I type the letter "v" into a text box. (int)'v' returns 118. 118 is the keyCode for F7 not the keyCode for "v" which is 86.
Sure enough my application is detecting that F7 has been hit.
This just seems straightforwardly wrong. Am I missing something here - I can't believe that no one else would be seeing this issue if I weren't.
Thanks in advance,
Julian.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这里发生了一些事情。调用 ((int)'[character]') 将返回该字符的十进制 ASCII 值。小写的 v 是 118。大写的 V 是 86。
查看 WatiN.Core.Element.KeyPress 的调用堆栈,最终会调用方法 SetValueWhenOnKeyPress 中的以下代码行> 在 IEFireEventHandler.cs 中。
addChar 是 GetKeyCodeEventProperty 中返回的 keyCode 项。 newValue 是用来设置元素值的,因此当您执行 myTextField.TypeText('v') 之类的操作时,会在文本框中键入小写 v 。
注意:WatiN 2.1 代码已为此进行了审查。
I think a couple things are happening here. Calling ((int)'[character]') is returning that character's decimal ASCII value. Lowercase v is 118. Uppercase V is 86.
Looking through the call stack for WatiN.Core.Element.KeyPress it eventually gets down to call the following line of code in method SetValueWhenOnKeyPress in IEFireEventHandler.cs.
addChar is the keyCode item returned in GetKeyCodeEventProperty. newValue is what is being used to set the Element's value, thus when you do something like myTextField.TypeText('v') a lowercase v is typed in your textbox.
Note: WatiN 2.1 code was reviewed for this.