【发布时间】:2017-01-10 13:30:00
【问题描述】:
我希望脚本在后台运行,并在按下 CTRL+1 之类的热键时将变量的内容“粘贴”到当前活动的文本字段中。我到目前为止的代码:
function Send($key)
{
$wsh.SendKeys($key)
}
$wsh = New-Object -ComObject WScript.Shell
$c1 = "Text to be sent #1"
$c2 = "Text to be sent #2"
$c3 = "Text to be sent #3"
$c4 = "Text to be sent #4"
$c0 = "Text to be sent #5"
switch ($check)
{
1 {Send($c1)}
2 {Send($c2)}
3 {Send($c3)}
4 {Send($c4)}
0 {Send($c0)}
default {Sleep(1)}
}
我尝试搜索,但找不到任何可行的解决方案。 我目前使用具有 similair 功能的 AutoIt 脚本,虽然我没有编写这个脚本,不幸的是我不认识作者。
#include < Misc.au3 >
Func _SendEx($ss, $warn = "")
Local $iT = TimerInit()
While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
If $warn <> "" And TimerDiff($iT) > 1000 Then
MsgBox(262144, "Avertissement", $warn)
EndIf
Sleep(50)
WEnd
Send($ss)
EndFunc;==>_SendEx
HotKeySet ("^1", "c1")
HotKeySet ("^2", "c2")
HotKeySet ("^3", "c3")
HotKeySet ("^4", "c4")
HotKeySet ("^0", "c0")
While True
Sleep (10000)
WEnd
Func c1 ()
_SendEx ("text 1")
EndFunc
Func c2 ()
_SendEx ("text 2")
EndFunc
Func c3 ()
_SendEx ("text 3")
EndFunc
Func c4 ()
_SendEx ("text 4")
EndFunc
Func c0 ()
_SendEx ("text 0")
EndFunc
我想在 powershell 中重新创建,如何为该功能分配热键?
【问题讨论】:
标签: powershell autoit