0

我正在寻找一种在 Linux 中使用反引号 (`) / 波浪号 (~) 键和其他键创建键盘快捷键的方法。在理想情况下:

  1. 按下波浪号什么都不做
  2. 在按下波浪号时按下另一个键会触发(可自定义的)快捷方式
  3. 在/不按另一个键之前释放波浪号时,只需发送波浪号击键。

我在 AutoHotKey for Windows 中有类似的东西,我一直在寻找一种在(任何)Linux 环境中重新创建它的方法。如果我可以让它工作,我会考虑使用任何 GUI,但当然更“通用”的解决方案会更好。

4

3 回答 3

1

我想我终于明白了!!

我使用xmodmapgrave键变成修饰符Hyper_L,如果在没有按下另一个键的情况下释放键,则使用XCape发送坟墓。

Xcape 旨在在meta没有其他键的情况下按下和释放 - 键(“Windows 键”)时打开应用程序菜单(“开始菜单”),因此作为额外的奖励,它也可以这样做。这意味着您既可以Meta用作修饰符,例如Meta-F打开文件管理器,也可以单独使用meta-key 打开胡须菜单。

如果一切正常,您可以使用 打开键盘设置管理器~-k,并且可以使用 ~-key 创建新的快捷键。因为这仍然很烦人并且不容易在不同系统之间移植,所以我包含了一些使用xfconf-query 的快捷方式,它们可能只在 Xfce 中有效。

这是我的脚本的基础知识:

#!/bin/sh

# reset pretty much ALL keyboard settings 
setxkbmap

# Free up the mod3 and mod4 flags from all keys it may be associated with:
xmodmap -e "clear mod3"
xmodmap -e "clear mod4"

# Add Hyper_L to the grave key (49)
xmodmap -e "keycode 49 = Hyper_L asciitilde grave asciitilde"

# You need a grave key somewhere else (!) so, bind it to an unused key:
xmodmap -e "keycode 250 = grave"

# Restore Mod4 but without Hyper_L (which was at location 4)
xmodmap -e "add mod4 = Super_L Super_R Super_L"

# Assign the mod3 to Hyper_L:
xmodmap -e "add mod3 = Hyper_L"

dist=100
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>Right -s "xdotool mousemove_relative -- $dist 0" --create -t string
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>Down  -s "xdotool mousemove_relative -- 0 $dist" --create -t string
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>Left  -s "xdotool mousemove_relative -- -$dist 0" --create -t string
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>Up    -s "xdotool mousemove_relative -- 0 -$dist" --create -t string
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>space -s "xdotool click 1" --create -t string

/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>k -s "xfce4-keyboard-settings" --create -t string

# (re)starting xcape to produce a ` after key-up if no other key was pressed
killall xcape
xcape -t5000 -e "#49=grave;Super_L=Control_L|Escape" &

可以在此处找到更扩展的脚本版本,以及更多快捷方式。

于 2017-01-18T04:59:48.957 回答
0

在另一台机器上切换到 Ubuntu 后,我还想像在 AHK 脚本中那样使用波浪号作为修饰键。

我对 ex 的不同工具进行了相当多的研究。xdotool、xev、autotools、xbindkeys 等等,终于找到了解决方案。以下是步骤。

  1. 安装 Autokey、python、python evded 模块、xte(sudo apt-get install xautomation)。
  2. 阅读一些关于 Autokey 以及它如何启动 python 脚本或创建热字串的信息。在 Autokey 中,我们可以设置一个热键来调用 python 脚本。因此,您可以将下面的 python 脚本分配给您的波浪号键,或者您计划创建的任何自定义热键。
  3. 这是所需的自定义功能(还没有完全移植到 linux,我用 autohotkey 编写了脚本,我很喜欢它。它让手粘在键盘上;))
    • 波浪号 + 向上箭头:将鼠标指针向上移动 100 个位置
    • 波浪号 + 向下箭头:将鼠标指针向下移动 100 个位置
    • 波浪号 + 右箭头:将鼠标指针向右移动 100 个位置
    • 波浪号 + 向左箭头:将鼠标指针向左移动 100 个位置
    • 波浪号 + Enter:鼠标左键单击(python 脚本中不存在)
    • 波浪号 + Alt + Enter:鼠标右键
  4. 我使用波浪号 (KEY_GRAVE) 作为修饰键。按下此键时,Autokey 会启动 python 脚本。脚本会循环运行,直到释放波浪号键。在循环中,脚本继续检测键盘输入。在向上箭头键 (KEY_UP) 按下时,脚本会发送命令以利用“xte”等相对位置(0,-100)移动鼠标。 from evdev import InputDevice, categorize, ecodes from select import select dev = InputDevice('/dev/input/event4') releasekey = False while releasekey==False: r,w,x = select([dev], [], []) for event in dev.read(): if event.type == ecodes.EV_KEY: #system.exec_command("xte 'mousermove 0 3'", False) #break if event.code == ecodes.KEY_UP: if event.value == 1: system.exec_command("xte 'mousermove 0 -100'", False) if event.code == ecodes.KEY_DOWN: if event.value == 1: system.exec_command("xte 'mousermove 0 100'", False) if event.code == ecodes.KEY_RIGHT: if event.value == 1: system.exec_command("xte 'mousermove 100 0'", False) if event.code == ecodes.KEY_LEFT: if event.value == 1: system.exec_command("xte 'mousermove -100 0'", False)
    if event.code == ecodes.KEY_GRAVE: if event.value == 0: releasekey = True break
  5. 您必须调整 dev = InputDevice(' /dev/input/event4 ') 行以分配正确的键盘名称。就我而言, event4 是我的键盘。你的可能不一样。您可以在 python-evdev 上查看方便的教程“阅读事件”。该代码实际上输出 /dev/input 下列出的键盘名称。实际上,我的脚本是该教程脚本的扩展。
  6. 唯一的问题是 python 脚本必须以 root 用户身份启动,否则无法访问键盘输入设备。您可以通过创建一个 udev 规则文件来克服这个问题,该文件更改设备的权限以使其可用于读写,例如。创建一个规则文件并添加这一行 KERNEL=='event4', MODE="0660"并加载规则。最后,您必须将自己添加到对设备具有读/写权限的 GROUP 中。可以使用 /dev/input 文件夹中的 ls -la 找到有关文件权限的信息。

我希望这个对你有用。起初它不起作用,然后喝杯咖啡并继续战斗直到它起作用;)

于 2016-09-16T21:51:57.500 回答
0

我不确定它是否适合您,但您应该检查:

这两个工具都允许您创建一些自定义操作和快捷方式。

这是 xdotool 的示例:https ://askubuntu.com/questions/212154/create-a-custom-shortcut-that-types-clipboard-contents

希望它有所帮助,祝你好运:)

布鲁诺

于 2015-08-24T12:50:00.583 回答