我正在寻找一种在 Linux 中使用反引号 (`) / 波浪号 (~) 键和其他键创建键盘快捷键的方法。在理想情况下:
- 按下波浪号什么都不做
- 在按下波浪号时按下另一个键会触发(可自定义的)快捷方式
- 在/不按另一个键之前释放波浪号时,只需发送波浪号击键。
我在 AutoHotKey for Windows 中有类似的东西,我一直在寻找一种在(任何)Linux 环境中重新创建它的方法。如果我可以让它工作,我会考虑使用任何 GUI,但当然更“通用”的解决方案会更好。
我正在寻找一种在 Linux 中使用反引号 (`) / 波浪号 (~) 键和其他键创建键盘快捷键的方法。在理想情况下:
我在 AutoHotKey for Windows 中有类似的东西,我一直在寻找一种在(任何)Linux 环境中重新创建它的方法。如果我可以让它工作,我会考虑使用任何 GUI,但当然更“通用”的解决方案会更好。
我想我终于明白了!!
我使用xmodmap将grave
键变成修饰符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" &
可以在此处找到更扩展的脚本版本,以及更多快捷方式。
在另一台机器上切换到 Ubuntu 后,我还想像在 AHK 脚本中那样使用波浪号作为修饰键。
我对 ex 的不同工具进行了相当多的研究。xdotool、xev、autotools、xbindkeys 等等,终于找到了解决方案。以下是步骤。
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
我希望这个对你有用。起初它不起作用,然后喝杯咖啡并继续战斗直到它起作用;)
我不确定它是否适合您,但您应该检查:
这两个工具都允许您创建一些自定义操作和快捷方式。
这是 xdotool 的示例:https ://askubuntu.com/questions/212154/create-a-custom-shortcut-that-types-clipboard-contents
希望它有所帮助,祝你好运:)
布鲁诺