我正在创建一个应用程序,我希望当用户打开我的应用程序时,它应该为自己创建一个热键,例如ctrl
+ alt
+ f
以便每次用户按下这些组合键时应用程序都会自动运行。
我知道如何通过右键单击应用程序并添加组合键在 Windows 中手动实现此目的,但我不知道如何以编程方式实现这一目标因为我不希望用户自己这样做。
您可以通过编程方式创建一个快捷方式文件 (*.lnk
)指向您的应用程序可执行文件,它还允许定义调用的热键。
The following example creates MyApp.lnk
on your Desktop, which launches Notepad, optionally via hotkey Ctrl+Alt+F; the hotkey takes effect instantly:
-
Caveat:仅保存快捷方式文件选择目录确保他们的热键定义生效坚持不懈地,即重新启动后继续工作。 (当前用户的)桌面可以工作 - 我不清楚其他目录也可以工作。
# Get the Desktop dir. path.
$desktopDir = [Environment]::GetFolderPath('Desktop')
# Create the shortcut object, initially in-memory only.
$shc =
(New-Object -ComObject 'Wscript.Shell').CreateShortcut("$desktopDir\MyApp.lnk")
# Set the target executable (name will do if in $env:PATH).
# If arguments must be passed, use the separate .Arguments property (single string)
$shc.TargetPath = 'notepad.exe'
# Assign the hotkey.
$shc.Hotkey = 'Ctrl+Alt+F'
# Save to disk (using the initially specified path).
$shc.Save()
请参阅文档WshShortcutCOM对象,上面创建了一个实例。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)