如何使用 WScript.Shell SendKeys 发送数字键盘击键?

发布于 2024-07-08 11:21:55 字数 669 浏览 5 评论 0原文

我正在尝试使用 WScript.Shell SendKeys 方法来模拟从数字键盘发送按键。

我有一个应用程序,正在使用 QTP 编写自动化测试。 它是一个基于 Web 浏览器的应用程序,输入输入到网页内的 Java 应用程序中。 输入仅接受数字键盘和 Enter 键的按键。

到目前为止,我正在使用这段代码:

Dim strInputKey
strInputKey = "{ENTER}"
Set objWsh = CreateObject("WScript.Shell")
Browser("Launch Browser").Page("Test Application").WebElement("Item ID").Click
objWsh.SendKeys strInputKey

这对于发送 Enter 键效果很好,但我不太清楚是否有办法发送数字键。 任何帮助将不胜感激。

我不确定是否有任何未记录的方法可以实现这一目标。 我已阅读 http://msdn.microsoft.com/ en-us/library/8c6yea83(VS.85).aspx 但它没有详细说明。

I am trying to use WScript.Shell SendKeys method to emulate sending a key press from the Number Pad.

I have an application that I am writing automated testing for using QTP. It is a Web Browser based application and the input is into a Java App within the web page. The input only accepts key presses from the Number Pad and the Enter key.

So far I am using this code:

Dim strInputKey
strInputKey = "{ENTER}"
Set objWsh = CreateObject("WScript.Shell")
Browser("Launch Browser").Page("Test Application").WebElement("Item ID").Click
objWsh.SendKeys strInputKey

This works fine for sending the Enter key, but I can't quite figure out if there is a way to send Number Keys. Any help would be greatly appreciated.

I am not sure if there are any undocumented ways of achieving this. I have read http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx but it doesn't go into great detail.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

入怼 2024-07-15 11:21:55

我没有代表对上述答案发表评论
objWsh.SendKeys chr(79) & chr(80) & chr(81)

但我认为这是不正确的

objWsh.SendKeys chr(79) & chr(80) & 字符(81)
首先,它发送字母 O、P、Q
他想要数字,比如 1234567890

,链接指向键盘扫描代码。我认为这些是为了知道按下了键盘上的哪个键。 它们与 ascii 代码不同。
79、80、81 是数字键盘/小键盘上某些数字的键盘扫描码。

但 Chr 使用 ascii 代码。 不是键盘扫描码。

此外,这里只是指定一个数字,因为不是通过按键来完成的,所以没有指定也不必指定使用了哪个键,因为没有使用键。

要发送按键一些数字(从数字键盘),与从顶行发送按键相同。 您只想发送一些号码。

如果他只想知道如何使用 sendkeys 发送数字,那么显然。

objWsh.SendKeys 12345
或者
字符串=“12345”
objWsh.SendKeys str

但如果提问者没有意识到 objWsh.SendKeys 12345 可以做到这一点,那么提问者可能只是感到困惑。 我从绿色勾号猜想,他投票了一个类似于 objWsh.SendKeys“OPQ”的答案。

我知道这是一个老问题,但为了有正确的问题和答案。

I don't have the rep to comment on the above answer that said
objWsh.SendKeys chr(79) & chr(80) & chr(81)

but I don't think it's correct

objWsh.SendKeys chr(79) & chr(80) & chr(81)
For a start, it sends the letters O,P,Q
And he wants numbers, like 1234567890

and the link goes to keyboard scan codes.. I think those are for knowing what key on the keyboard was pressed. They are different from ascii codes.
79,80,81 are the keyboard scan codes for some numbers on the number pad / numpad.

Chr though, uses ascii codes. not keyboard scan codes.

Furthermore, just specifying a digit, here, since it isn't done by pressing a key, it doesn't specify and needn't specify, which was key was used, since a key wasn't used.

To sendkeys some numbers (from the number pad), is just same as sending keys from the top row. You just want to send some numbers.

If all he wants to know is how to use sendkeys to send digits, then obviously.

objWsh.SendKeys 12345
or
str="12345"
objWsh.SendKeys str

But if the questioner didn't realise that objWsh.SendKeys 12345 would do it, then perhaps the questioner is just confused. I guess from the green tick, he voted an answer that is like objWsh.SendKeys "OPQ".

I am aware that this is an old question, but for the sake of haing correct questions and answers..

扎心 2024-07-15 11:21:55

您需要使用数字键盘的键码。

以下是其中的列表:
http://www.empirisoft.com/directrt/help/_helpcontents。 htm?directrt_key_codes.htm

因此,要发送“123”,您需要执行以下操作:

objWsh.SendKeys chr(79) & chr(80) & chr(81) 

You'll need to use the keycodes for the number pad.

Here's a list of them:
http://www.empirisoft.com/directrt/help/_helpcontents.htm?directrt_key_codes.htm

So to send "123", you would need to do:

objWsh.SendKeys chr(79) & chr(80) & chr(81) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文