You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

xdotool key无法在运行终端外的其他终端生效问题求助

问题:xdotool无法向非当前gnome-terminal窗口发送按键操作

我正在编写一个bash脚本,目标是打开多个gnome-terminal窗口、运行指定程序并向这些窗口发送按键操作。目前前两步已实现,但第三步用xdotool发送按键时,发现xdotool key命令仅对运行该命令的当前终端生效,无法作用于其他终端窗口。

尝试过的操作及结果

  • 当前终端直接执行:
    执行命令:

    xdotool key a
    

    终端正常响应:

    [uname@computer ~]$ xdotool key a
    a[uname@computer ~]$ a
    
  • 链式命令操作多终端:
    打开另一个终端后,执行以下链式命令:

    xdotool search --class gnome-terminal key --window %@ a
    

    结果是两个终端均无任何反应。根据xdotool文档,search命令应将找到的窗口加入WINDOW STACK,后续命令可通过%@或%N引用,但实际无效。换用xterm测试,结果一致。

  • 脚本中分步骤执行:
    脚本内容:

    xdotool search --class gnome-terminal
    xdotool key --window %@ w
    

    执行脚本后输出:

    [uname@computer ~]$ ./test_xdo.sh
    50331649
    50339261
    50332317
    There are no windows on the stack, Can't continue.
    

运行环境

[uname@computer ~]$ cat /etc/redhat-release
Red Hat Enterprise Linux release 8.5 (Ootpa)
[uname@computer ~]$ uname -r
4.18.0-348.20.1.el8_5.x86_64
[uname@computer ~]$ xdotool -v
xdotool version 3.20200624.1

内容的提问来源于stack exchange,提问作者Adam Mills

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 12:42:19