linux 快捷应用程序_如何为任何Linux应用程序定制快捷键

linux 快捷应用程序

One of the more annoying problems with Linux has always been the lack of AutoHotkey support, so you couldn’t customize your shortcut keys—but now with the open source application AutoKey, you can do that and more.

Linux上最烦人的问题之一就是缺乏对AutoHotkey的支持,因此您无法自定义快捷键,但是现在有了开源应用程序AutoKey,您可以做到这一点甚至更多。

AutoKey is a desktop automation utility that lets you manage blocks of text and use abbreviations and hotkeys to save yourself time while typing—but you can also use it to remap hotkeys in applications. For instance, if your favorite application used Ctrl+Q to quit and you didn’t want it to, you could remap that key using AutoKey.

AutoKey是一个桌面自动化实用程序,可让您管理文本块并使用缩写和热键来节省键入时的时间,但您也可以使用它来重新映射应用程序中的热键。 例如,如果您最喜欢的应用程序使用Ctrl + Q退出但又不想退出,则可以使用AutoKey重新映射该键。

场景 (The Scenario)

For our test scenario today, I’m going to remap the Ctrl+T key combination to Alt+T instead. Why, you ask? The Ctrl+T shortcut key is used in every browser to open a new tab, but since I use Google Chrome and like to open new tabs constantly to search, the Alt+T shortcut key is a lot easier for me to hit without moving my hands from the front row.

对于今天的测试场景,我将把Ctrl + T组合键重新映射为Alt + T。 你为什么问? 在每个浏览器中都使用Ctrl + T快捷键来打开新标签页,但是由于我使用的是Google Chrome浏览器,并且喜欢不断打开新标签页进行搜索,因此Alt + T快捷键对我来说更容易点击而不移动前排的双手。

linux 快捷应用程序_如何为任何Linux应用程序定制快捷键

To accomplish this task, we’ll use the amazing AutoKey tool, which is a lot like AutoHotkey on Windows, except it’s made for Linux and is capable of using Python scripts.

为了完成此任务,我们将使用令人惊叹的AutoKey工具,该工具与Windows上的AutoHotkey十分相似,只是它是为Linux制作的,并且能够使用Python脚本。

安装自动** (Installing AutoKey)

You’ll want to open up the Synaptic Package Manager and do a quick search for autokey, check the box, and then install the package. You could also install it using the apt-get command like this:

您将要打开Synaptic软件包管理器并快速搜索autokey ,选中该复选框,然后安装该软件包。 您也可以使用apt-get命令安装它,如下所示:

sudo apt-get install autokey

sudo apt-get install autokey

linux 快捷应用程序_如何为任何Linux应用程序定制快捷键

用自动键重新映射快捷键 (Remapping Shortcut Keys with AutoKey)

Once you’ve got the utility installed, you can open up the configuration through the tray icon and create a New Phrase. The name on the left-hand side doesn’t mean anything, I just like to name them according to the hotkey that I’ll be assigning.

安装该实用程序后,您可以通过任务栏图标打开配置并创建一个新短语。 左侧的名称没有任何意义,我只是想根据将要分配的热键为它们命名。

Use the Set button next to Hotkey to assign the hotkey you want to use, click the modifier key—in this case, I’m assigning Alt, and then click the Press to Set button and the key you want to use. For my example, I’m using Alt+t, and you’ll notice the character is lowercase, which is important—if you pressed Shift+T there, AutoKey would get confused.

使用“热键”旁边的“设置”按钮来分配您要使用的热键,单击修改键(在这种情况下,我要分配Alt,然后单击“按设定”按钮和您要使用的键)。 在我的示例中,我使用的是Alt + t,您会注意到该字符为小写字母,这一点很重要-如果在此按Shift + T,则AutoKey会感到困惑。

linux 快捷应用程序_如何为任何Linux应用程序定制快捷键

Once that’s done, you can put the following into the text box:

完成后,您可以在文本框中输入以下内容:

<ctrl>+t

<ctrl> + t

Click the save button, and you’re done. Now you can open up your browser and use the Alt+T combination instead of Ctrl+T, and it should open up a new tab.

单击保存按钮,就完成了。 现在,您可以打开浏览器,并使用Alt + T组合键代替Ctrl + T,它将打开一个新选项卡。

How does this work? When you press the Alt+T hotkey that you’ve assigned, AutoKey sends the keystrokes to the currently active application, and since the keystrokes in this case are Ctrl+T, Google Chrome assumes that you pressed the shortcut key for a new tab, and responds accordingly.

这是如何运作的? 当您按已分配的Alt + T热键时,“自动键”会将键击发送到当前处于活动状态的应用程序,由于这种情况下的键击为Ctrl + T,因此Google Chrome会假定您按下了新标签的快捷键,并据此做出回应。

按窗口过滤 (Filtering by Window)

The only problem is that the shortcut key now is activated for all windows. To fix this, we can setup a window filter using the Set button, and then type in something similar to this:

唯一的问题是现在所有窗口都**了快捷键。 要解决此问题,我们可以使用“设置”按钮设置一个窗口过滤器,然后输入与此类似的内容:

.*Google.*Chrome

。*谷歌浏览器

linux 快捷应用程序_如何为任何Linux应用程序定制快捷键

You might be wondering what the .* is all about—this filter uses regular expressions to find the window title, so you’ll need to use .* to match any characters that aren’t specified, including the space in this case. Note: You could use a single period character to represent a space if you want.

您可能想知道。*的全部含义–该过滤器使用正则表达式来查找窗口标题,因此您需要使用。*来匹配所有未指定的字符,在这种情况下包括空格。 注意:如果需要,可以使用单个句点字符来表示空格。

在自动键中使用特殊键 (Using Special Keys in AutoKey)

When you’re creating a new phrase, you can use the following special codes to simulate pressing one of the special keys. There’s actually a much bigger list of special keys, but these are probably the most important ones you’ll need to use:

创建新短语时,可以使用以下特殊代码来模拟按下特殊键之一。 实际上,特殊键列表更大 ,但是这些可能是您需要使用的最重要的

  • <ctrl>

    <ctrl>
  • <alt>

    <alt>
  • <escape>

    <转义>
  • <tab>

    <tab>
  • <shift>

    <班次>
  • <super>  = Windows Key

    <super> = Windows键
  • <enter>

    <输入>

Combining Keys

组合键

If you want to combine together a number of keys, you’ll use the + character, like this:

如果要将多个键组合在一起,则可以使用+字符,如下所示:

<ctrl>+<shift>+<tab>

<ctrl> + <shift> + <tab>

If you needed to actually insert a + symbol, you’d need to use <np_add> instead.

如果需要实际插入+符号,则需要使用<np_add>。

自动键摇滚! (AutoKey Rocks!)

There’s any number of uses for this technique besides just remapping shortcut keys—you could automate a series of keystrokes to perform a task, for instance. The possibilities are endless—but what would you use it for?

除了重新映射快捷键之外,此技术还有许多用途-例如,您可以自动执行一系列击键来执行任务。 可能性无穷无尽,但是您将用它做什么呢?

翻译自: https://www.howtogeek.com/howto/26913/how-to-customize-shortcut-keys-for-any-linux-application/

linux 快捷应用程序

相关文章: