在 Powershell 中发送密钥 alt+n {TAB} {ENTER} [英] Send Keys in Powershell alt+n {TAB} {ENTER}

查看:90
本文介绍了在 Powershell 中发送密钥 alt+n {TAB} {ENTER}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在自动每天从安全站点下载 zip 文件.脚本已准备就绪,使用 Internet Explorer 登录并转到所需位置,然后单击下载按钮,脚本按预期工作到这里.

Am in process of automating the daily download of a zip file from secure site. Script is ready which uses the internet explorer to login and go to the required location and then click on download button, script works as expected till here.

点击下载按钮后,会提示点击保存按钮.已尝试使用以下

Upon clicking download button, it prompts to click on save button. Have tried with send keys with below

$wshell = New-Object -ComObject WScript.Shell    
$id = (gps iex* | where {$_.MainWindowTitle -match "Title"}).id    
$wshell.AppActivate($id)    
start-sleep 1    
$wshell.SendKeys("%{n}")    
Start-Sleep 1  

想要发送键 (Alt+n + TAB + ENTER),尝试通过更改一些内容但最终得到相同的结果.

want to send keys (Alt+n + TAB + ENTER), tried by changing few things but end up with the same result.

推荐答案

使用 System.Windows.Forms.SendKeys 类模拟发送键.

To emulate send keys you want to use System.Windows.Forms.SendKeys class.

加号 (+)、脱字符 (^)、百分号 (%)、波浪号 (~) 和括号 () 对 SendKeys 有特殊意义.指定其中之一这些字符,将其括在大括号 ({}) 中

The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to SendKeys. To specify one of these characters, enclose it within braces ({})

在您的情况下,根据文档,代码示例应如下所示:

In your case, according to documentation, code sample should look like:

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait("%n{TAB}{ENTER}")

地点:

  • % 代表 ALT 按钮;
  • n 代表 n 按钮;
  • {TAB} 代表 TAB 按钮;
  • {ENTER} 代表 ENTER 按钮.
  • % stands for ALT button;
  • n stands for n button;
  • {TAB} stands for TAB button;
  • {ENTER} stands for ENTER button.

请按照文档页面查看可用选项的完整列表 这里.

Please follow the documentation page to can see complete list of available options here.

这篇关于在 Powershell 中发送密钥 alt+n {TAB} {ENTER}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆