为 Windows 制作热键的最简单方法是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/976889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the easiest way to make a hotkey for windows?
提问by
For example , you push Ctrl+Vand insert the buffer content into the window. How can I create my own hotkeys like that? Sorry for noobish question.
例如,您按下Ctrl+V并将缓冲区内容插入到窗口中。我怎样才能像这样创建自己的热键?很抱歉提出了一个愚蠢的问题。
回答by Copas
A great way to do this quickly and easily is with a script language that focuses on macro programming. My favorite is AutoItas it says in a clip from the AutoIt help file...
一种快速轻松地做到这一点的好方法是使用专注于宏编程的脚本语言。我最喜欢的是AutoIt,因为它在 AutoIt 帮助文件的剪辑中说...
AutoIt was initially designed for PC "roll out" situations to reliably automate and configure thousands of PCs. Over time it has become a powerful language that supports complex expressions, user functions, loops and everything else that veteran scripters would expect.
AutoIt 最初是为 PC“推出”情况设计的,以可靠地自动化和配置数千台 PC。随着时间的推移,它已经成为一种强大的语言,支持复杂的表达式、用户函数、循环以及资深脚本编写者所期望的一切。
Writing a hotkey application in AutoIt couldn't be easier. For example lets say for some reason (to obscure to mention) you would like Alt+Qto react as number pad key 7 in a particular situation possibly so you don't have to reach across the keyboard for it. Here's some code that does that...
在 AutoIt 中编写热键应用程序再简单不过了。例如,假设出于某种原因(模糊不清),您可能希望Alt+Q在特定情况下作为数字键盘键 7 做出反应,因此您不必跨过键盘。这里有一些代码可以做到这一点......
Func _num7()
Send("{numpad7}")
EndFunc
HotKeySet("!{q}","_num7")
While 1
sleep(10)
WEnd
If that's not straight forward enough the AutoIt help file and forumsare very helpful. Not to mention a (very) few AutoIt developers are available on SO if you end up with any AutoIt specific questions.
如果这还不够直接,AutoIt 帮助文件和论坛非常有帮助。如果您最终遇到任何 AutoIt 特定问题,更不用说(非常)少数 AutoIt 开发人员可在 SO 上使用。
In the example above lets say you only wanted the hotkeys to be active when a particular application was in use so as to not interfere with other hotkeys. This code would accomplish just that.
在上面的示例中,假设您只希望在使用特定应用程序时热键处于活动状态,以免干扰其他热键。这段代码就可以做到这一点。
; The comment character in AutoIt is ;
Local $inTargetProg = False
Func _num7()
Send("{numpad7}")
EndFunc
While 1
If WinActive("Target Application Window Title") and Not $inTargetProg Then
HotKeySet("!{q}","_num7") ; binds Alt+Q to the _num7() function
$inWC3 = True
EndIf
If Not WinActive("Target Application Window Title") and $inTargetProg Then
HotKeySet("!{q}") ; UnBind the hotkey when not in use
$inWC3 = False
EndIf
sleep(5)
WEnd
回答by William B-R
I've been using AutoHotkeyat work for the best part of a year now.
我一年中大部分时间都在工作中使用AutoHotkey。
I just save the following file in my Windows Startup folder.
我只是将以下文件保存在我的 Windows 启动文件夹中。
keyboard_shortcuts.ahk
键盘快捷键.ahk
#SingleInstance force
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
Menu, Tray, Icon, Shell32.dll, 44
; Starting Directory for cmd.exe
EnvGet, HOMEDRIVE, HOMEDRIVE
EnvGet, HOMEPATH, HOMEPATH
#i:: Run, notepad
#f:: Run, firefox
#c:: Run, cmd /k, %HOMEDRIVE%%HOMEPATH%
#m:: Run, mailto:
#b:: Run, mailto:[email protected]
"#b"means Winkey+B
"#b"表示Winkey+B
"Run, mailto:[email protected]"open a black email to my boss.
“跑,mailto:[email protected]”打开一封黑色邮件给我的老板。
#b:: Run, mailto:[email protected]
回答by sean e
Per-process keyboard shortcuts like Ctrl+Vare usually defined in a resource (.rc) file and loaded via the Win32 API LoadAccelerators.
每个进程的键盘快捷键(如Ctrl+)V通常在资源 (.rc) 文件中定义,并通过 Win32 API LoadAccelerators加载。
Windows-wide keyboard shortcuts (hotkeys) are registered using the Win32 API RegisterHotKey.
使用 Win32 API RegisterHotKey 注册Windows 范围的键盘快捷键(热键)。
回答by Louis Davis
You can create a simple hotkey in Windows by creating a shortcut and then assign a shortcut key to it. I have done this for launching some command line apps with parameters. The following link explains using a shortcut key to an app to mute the volume:Mute
您可以通过创建快捷方式然后为其分配快捷键来在 Windows 中创建一个简单的热键。我这样做是为了启动一些带参数的命令行应用程序。以下链接说明使用应用程序的快捷键将音量静音:静音
Just replace the Target: and Shortcut Key: in the shortcut properties with whatever you need for your purposes.
只需将快捷方式属性中的 Target: 和 Shortcut Key: 替换为您需要的任何内容即可。
回答by Nicolas Paglia
Ok...the easiest way, for example On you desktop, you can use accelerated command by right click the icon > properties > shortcut key; Click on the empty space and it will seem like nothing happens, but this is when you assign your "hotkey" I used Shift+1and whenever I combine Shift+1Firefox opens.
好的...最简单的方法,例如在您的桌面上,您可以通过右键单击图标>属性>快捷键来使用加速命令;单击空白处,似乎什么也没有发生,但这是在您分配“热键”时我使用的Shift+1以及每当我组合Shift+ 1Firefox 打开时。
回答by Abiram
Simple script with windows with no third party software required.Just save as .vbs file and double click
简单的 windows 脚本,无需第三方软件。只需另存为 .vbs 文件并双击
currentDirectory = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))
Set objShell = WScript.CreateObject("WScript.Shell")
Set lnk = objShell.CreateShortcut(currentDirectory & "search.LNK")
lnk.TargetPath = currentDirectory & "search.bat"
lnk.Arguments = ""
lnk.Description = "Abiram's search"
lnk.HotKey = "SHIFT+CTRL+C"
lnk.WindowStyle = "7"
lnk.WorkingDirectory = currentDirectory
lnk.Save
'Clean up
Set lnk = Nothing
Change the lnk.TargetPath to include your exe file or batch file to be called.
更改 lnk.TargetPath 以包含要调用的 exe 文件或批处理文件。
回答by samoz
First, welcome to Stack Overflow!
首先,欢迎来到 Stack Overflow!
Second, this is a program by program thing. The only reason that Ctrl+Cor Ctrl+Vworks across different programs is because there is operating system support for the clipboard and many programs follow the convention of using Ctrl+Cor Ctrl+V. In your own programs, you can bind the keys however you like! For more details, we'll need more information about your program.
其次,这是一个程序一个程序的事情。Ctrl+C或Ctrl+V在不同程序中工作的唯一原因是操作系统支持剪贴板,并且许多程序遵循使用Ctrl+C或Ctrl+的约定V。在您自己的程序中,您可以随意绑定密钥!有关更多详细信息,我们需要有关您的计划的更多信息。
If you want to make actual hotkeys for Windows itself, I'm not sure how (nor if you are able) to make your own hotkeys. You might want to look into AutoIt, which is a free program that can do all sorts of things you might want to use a hotkey for, such as automatically clicking through menus, etc.
如果您想为 Windows 本身制作实际的热键,我不确定如何(也不知道您是否能够)制作自己的热键。您可能需要查看AutoIt,这是一个免费程序,可以执行您可能想要使用热键执行的各种操作,例如自动单击菜单等。