[英]Mouse events in terminal emulator
Question题
Is it possible, in a terminal emulator, to run a command whenever a mosue event happens?在终端模拟器中,是否可以在发生 mosue 事件时运行命令?
What I've tried我试过的
I think I'm halfway there - using echo -e "\\e[?1003h"
(see here for details) and waving the mouse about over the terminal produces a desirable effect of printing a bunch of characters, related to the occurred mouse event.我想我已经成功了 - 使用echo -e "\\e[?1003h"
(see here for details) 并在终端上挥动鼠标会产生打印一堆字符的理想效果,与发生的鼠标事件相关. (Note: echo -e "\\e[?1003l"
turns this off) (注意: echo -e "\\e[?1003l"
关闭此功能)
echo -e "\e[?1003h"
# move mouse over terminal window, in the character input line, NOT to stdout:
> CF*CC+C@,C;.C:/C8/C8/C8/C8/C9/C9/C9/C90C90C80C81C81C81C81C81C90C:/C;/C;.C<.C<.
# After deleting that, I enter:
> echo -e "\e[?1003l"
# mouse move, all is quiet
I've also tried hooking it up to output to a file.我也试过把它连接起来输出到一个文件。 This was to see if I could watch the file and run a command according to that.这是为了看看我是否可以查看文件并根据该文件运行命令。 It went as follows:它是这样的:
> echo -e "\e[?1003h" >> file.txt
# elevator music whilst I move the mouse about
> echo -e "\e[?1003l"
# move mouse a bit, nothing
> cat file.txt
# nothing but blank lines, fair enough. But, mouse moves and in the terminal input is printed...
> CF*CC+C@,C;.C:/C8/C8/C8/C8/C9/C9/C9/C90C90C8 ...
# Delete that output, and then I type:
> echo -e "\e[?1003l"
# mouse moves, no output
What I want我想要的是
How can I either capture this output so that it is going to stdout
, or to a file, so that I can then use the changing output to trigger running a command?我怎样才能捕获这个输出,以便它转到stdout
或文件,以便我可以使用不断变化的输出来触发运行命令? If that's not possible, is there any other way to capture when a mouse click occurs in a terminal emulator, with the event coordinates?如果这是不可能的,有没有其他方法可以在终端模拟器中发生鼠标单击时使用事件坐标进行捕获?
It's not output, it's input.不是输出,是输入。
There are multiple ways to read input in bash.有多种方法可以在 bash 中读取输入。 Here's one that reads everything until stopped:这是读取所有内容直到停止的一个:
echo -e "\e[?1003h"
echo "Press enter and then ctrl-d to stop reading"
cat > myfile
When done and correctly exited with Enter and Ctrl+D you can inspect myfile
to see all the mouse events.完成并使用 Enter 和 Ctrl+D 正确退出后,您可以检查myfile
以查看所有鼠标事件。
A proper mouse application would disable local echo and terminal buffering before reading and decoding the escape sequences from the terminal.适当的鼠标应用程序会在从终端读取和解码转义序列之前禁用本地回声和终端缓冲。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.