xdotool 搞乱键盘输入

xdotool 搞乱键盘输入

我正在尝试使用 xev 和 xdotool 创建一些脚本,以允许我在 Linux 中记录和重播宏。我已经使用 xev 进行了录制,并且重播大部分都可以工作,但似乎使我的 X 会话处于奇怪的状态。我有一个这样的宏文件:

keydown e
keyup e
keydown c
keydown h
keyup c
keydown o
keyup h
keyup o
keydown space
keyup space
keydown apostrophe
keyup apostrophe
keydown h
keydown i
keyup h
keyup i
keydown apostrophe
keyup apostrophe

我正在尝试将它与cat macro.txt | xargs xdotool.这会在终端中输入我的文本,但完成后,我的大部分按键都不再起作用;他们要么打印出控制字符,要么什么也不做。我不得不重新启动计算机几次才能重新设置。知道如何避免这种情况或发生了什么吗?或者甚至是一个好的 Linux 宏工具可能是什么?

答案1

我使用 Linux Mint 的键盘快捷键制作了自己的自定义宏并添加了自定义快捷键。我设法通过使用使其工作--clearmodifiers,如下所示:

xdotool key --clearmodifiers Up

看看是否有帮助。

另外,这是手册上所说的:

CLEARMODIFIERS 任何带有 --clearmodifiers 标志的命令都将尝试在命令期间清除任何活动的输入修饰符,并在之后恢复它们。

   For example, if you were to run this command:
    xdotool key a

   The result would be 'a' or 'A' depending on whether or not you were holding the shift key on your keyboard. Often it is undesirable to have any modifiers active, so you can tell xdotool to clear any active modifiers.

   The order of operations if you hold shift while running 'xdotool key --clearmodifiers a' is this:

   1. Query for all active modifiers (finds shift, in this case)
   2. Try to clear shift by sending 'key up' for the shift key
   3. Runs normal 'xdotool key a'
   4. Restore shift key by sending 'key down' for shift

   The --clearmodifiers flag can currently clear of the following:

   ·   any key in your active keymap that has a modifier associated with it.  (See xmodmap(1)'s 'xmodmap -pm' output)

   ·   mouse buttons (1, 2, 3, 4, and 5)

   ·   caps lock

相关内容