为 Windows 制作热键最简单的方法是什么?

发布于 2024-07-23 04:55:53 字数 84 浏览 3 评论 0原文

例如,您按 Ctrl+V 并将缓冲区内容插入到窗口中。 我怎样才能创建自己的热键呢? 抱歉问了个新手问题。

For example , you push Ctrl+V and insert the buffer content into the window. How can I create my own hotkeys like that? Sorry for noobish question.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

为你拒绝所有暧昧 2024-07-30 04:55:53

快速、轻松地完成此任务的一个好方法是使用专注于宏编程的脚本语言。 我最喜欢的是 AutoIt,正如它在 AutoIt 帮助文件的剪辑中所说的那样......

AutoIt 最初是为 PC 设计的
可靠地“推出”情况
自动化和配置数千个
件。 随着时间的推移,它已经成为一个
强大的语言支持
复杂的表达式、用户函数、
循环和其他一切老手
脚本编写者会期望。

在 AutoIt 中编写热键应用程序再简单不过了。 例如,假设出于某种原因(难以提及),您希望 Alt+Q 在特定情况下反应为数字键盘键 7,因此您可能不会必须越过键盘才能找到它。 这里有一些代码可以做到这一点...

Func _num7()
    Send("{numpad7}")
EndFunc

HotKeySet("!{q}","_num7")

While 1
    sleep(10)
WEnd

如果这还不够直接,请查看 AutoIt 帮助文件和 论坛非常有帮助。 更不用说如果您最终遇到任何 AutoIt 特定问题,(非常)少数 AutoIt 开发人员可以提供帮助。

在上面的示例中,假设您只希望在使用特定应用程序时激活热键,以免干扰其他热键。 这段代码就可以完成这个任务。

; 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

A great way to do this quickly and easily is with a script language that focuses on macro programming. My favorite is AutoIt as it says in a clip from the AutoIt help file...

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.

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+Q to 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...

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 forums are very helpful. Not to mention a (very) few AutoIt developers are available on SO if you end up with any AutoIt specific questions.

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
网名女生简单气质 2024-07-30 04:55:53

Ctrl+V 这样的每进程键盘快捷键通常在资源 (.rc) 文件中定义,并通过 Win32 API 加载加载加速器

Windows 范围的键盘快捷键(热键)使用 Win32 API 注册热键

Per-process keyboard shortcuts like Ctrl+V are usually defined in a resource (.rc) file and loaded via the Win32 API LoadAccelerators.

Windows-wide keyboard shortcuts (hotkeys) are registered using the Win32 API RegisterHotKey.

转身以后 2024-07-30 04:55:53

我在工作中使用 AutoHotkey 已经有一年的时间了。

我只是将以下文件保存在 Windows 启动文件夹中。

keyboard_shortcuts.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” 表示 Winkey+B

“运行,mailto:[email protected]" 打开一封发给我老板的黑色电子邮件。

#b:: Run, mailto:[email protected]

I've been using AutoHotkey at work for the best part of a year now.

I just save the following file in my Windows Startup folder.

keyboard_shortcuts.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

"Run, mailto:[email protected]" open a black email to my boss.

#b:: Run, mailto:[email protected]
才能让你更想念 2024-07-30 04:55:53

您可以通过创建快捷方式在 Windows 中创建简单的热键,然后为其分配快捷键。 我这样做是为了启动一些带有参数的命令行应用程序。
以下链接介绍了如何使用应用程序的快捷键将音量静音:静音

只需将快捷方式属性中的“目标:”和“快捷键:”替换为您需要的任何内容即可。

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

Just replace the Target: and Shortcut Key: in the shortcut properties with whatever you need for your purposes.

尸血腥色 2024-07-30 04:55:53

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

更改 lnk.TargetPath 以包含要调用的 exe 文件或批处理文件。

Simple script with windows with no third party software required.Just save as .vbs file and double click

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.

春花秋月 2024-07-30 04:55:53

好的...最简单的方法,例如在桌面上,您可以通过右键单击图标>来使用加速命令 属性> 快捷键; 单击空白处,似乎什么也没有发生,但这是当您分配“热键”时,我使用了 Shift+1 ,每当我组合 Shift 时+1 Firefox 将打开。

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+1 and whenever I combine Shift+1 Firefox opens.

海风掠过北极光 2024-07-30 04:55:53

首先,欢迎来到 Stack Overflow!

其次,这是一个逐个项目的事情。 Ctrl+CCtrl+V 跨不同程序工作的唯一原因是因为有操作系统支持对于剪贴板,许多程序都遵循使用 Ctrl+CCtrl+V 的约定。 在您自己的程序中,您可以随意绑定按键! 如需了解更多详情,我们需要有关您的计划的更多信息。

如果您想为 Windows 本身制作实际的热键,我不确定如何(也不知道您是否能够)制作自己的热键。 您可能需要研究 AutoIt,这是一个可以执行各种操作的免费程序您可能想要使用热键进行的操作,例如自动单击菜单等。

First, welcome to Stack Overflow!

Second, this is a program by program thing. The only reason that Ctrl+C or Ctrl+V works across different programs is because there is operating system support for the clipboard and many programs follow the convention of using Ctrl+C or 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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文