有没有办法使用powershell点击应用程序中的按钮 [英] Is there a way to click on button in application using powershell

查看:52
本文介绍了有没有办法使用powershell点击应用程序中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 powershell 代码,我想打开应用程序并单击任何选项.比如打开 Notepad++ 并点击文件 -->new

using powershell code i would like to open the application and click on any option. like open Notepad++ and click on file -->new

这是在powershell控制台中运行的独立脚本

This is independent script which run in powershell console

我试图像这样抓取 Notepad++ 窗口句柄

i tried to grab the Notepad++ window handle like this

$WindowHandle = Get-Process | Where-Object { $_.MainWindowTitle -Match $WindowTitle } | Select-Object -ExpandProperty MainWindowHandle

但我无法点击它.

打开记事本++

start-process "C:\Program Files\Notepad++\notepad++.exe"

抓取窗口

 $WindowHandle = Get-Process | Where-Object { $_.MainWindowTitle -Match $WindowTitle } | Select-Object -ExpandProperty MainWindowHandle

任何可以帮助我在记事本++上获取控件并单击选项或按钮的代码片段.

any code snippet which can help me in grabbing the control on notepad++ and click on options or buttons.

推荐答案

如果您想做的所有操作都有快捷方式,您只需将按键发送到窗口即可.

If all the actions you want to do have a shortcut, you could just send the keys to the window.

例如要打开一个新文件,您可以使用 CTRL + N

For example to open a new file you can use CTRL + N

start-process "C:\Program Files\Notepad++\notepad++.exe"
$WindowHandle = Get-Process | Where-Object { $_.MainWindowTitle -Match $WindowTitle } | Select-Object -ExpandProperty MainWindowHandle

[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
[System.Windows.Forms.SendKeys]::SendWait("^{n}")

当您在 Notepad++ 中按 ALT 时,它会显示您可以用来打开不同菜单的快捷方式.

When you press ALT in Notepad++ it will show you the shortcuts you can use to open the different menus.

要打开File,您可以使用ALT+F(F 有下划线,表示这是快捷方式).之后,您可以使用按键向下/向上导航以选择您想要的内容.大多数应用程序都会有这种行为.

To open File, you can use ALT+F (The F is underlined, meaning that's the shortcut). After that you could navigate down/up using keys to select what you want. Most applications will have this behavior.

除此之外,在 Notepad++ 中,您还可以将几乎任何操作映射到组合键.但是,这意味着您的脚本只能在您的 PC 上使用您的设置运行.

Besides that, in Notepad++ you could also map pretty much any action to a key combination. However, this would mean your script only works on your PC, with your settings.

这篇关于有没有办法使用powershell点击应用程序中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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