如何在 bash 中获得 MouseMove 和 MouseClick? [英] how to get MouseMove and MouseClick in bash?

查看:25
本文介绍了如何在 bash 中获得 MouseMove 和 MouseClick?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在 bash 脚本中为我自己的简单操作系统事件获取 MouseClick 和 MouseMove 事件.

I'm wondering how to get the MouseClick and MouseMove events in bash scripting for my own simple OS events.

请告诉我如何获得这些事件.

Please tell me how to get that events.

推荐答案

xterm 终端模拟器定义了一些控制序列来进行鼠标跟踪,您可以在下面的鼠标跟踪部分了解更多关于它们的信息文档 ctlseqs 用于 xterm 分发.如果您安装了 xterm,您可能会在 /usr/share/doc/xterm/ctlseqs.txt.gz 或类似路径中获得一份副本.

The xterm terminal emulator defines some control sequences to do mouse tracking, you can learn more about them in the section Mouse Tracking in the document ctlseqs for the xterm distribution. If you have xterm installed, you'll probably have a copy at /usr/share/doc/xterm/ctlseqs.txt.gz or a similar path.

在 X Window 系统上运行的大多数终端模拟器(例如:Konsole、gnome-terminal、eterm 等)至少理解其中一些控制序列.如果您想直接在 Linux 的虚拟终端之一上使用它们,您可能必须运行 gpm(8).

Most terminal emulators running on the X Window System (e.g: Konsole, gnome-terminal, eterm, ...) understand at least some of these control sequences. If you want to use them directly on one of Linux's virtual terminals, you'll probably have to run gpm(8).

有多种控制序列可用于启用和禁用鼠标移动报告:

There are several control sequences for enabling and disabling mouse movement reporting:

  • 9 -> X10 鼠标报告,为了与 X10 的 xterm 兼容,报告按下按钮.
  • 1000 -> X11 鼠标报告,关于按钮按下和释放的报告.
  • 1001 -> 突出显示报告,用于报告鼠标突出显示.
  • 1002 -> 按钮移动报告,当按下按钮时报告移动.
  • 1003 -> 所有运动报告,报告所有运动.

控制序列是 CSI ?数字 h 用于启用和 CSI ?编号 l 用于禁用.CSI 是 ESC [ 或字符 0x9b.因此,您可以按如下方式使用它们:

The control sequence is CSI ? number h for enabling and CSI ? number l for disabling. CSI is either ESC [ or character 0x9b. So, you could use them as follows:

echo -e "e[?1000h"

然后,您会在按下按钮时得到一堆字符,详情请参阅 ctlseqsconsole_codes(4).然后,您可以使用以下命令禁用鼠标跟踪:

Then, you'll get a bunch of characters on button press, see ctlseqs or console_codes(4) for details. Then, you can disable mouse tracking with:

echo -e "e[?1000l"

不幸的是,以前的鼠标报告模式最多只能处理 223 (255 - 32) 或在某些情况下 95 (127 - 32) 的坐标.所以有一些新的开关来改变报告鼠标坐标的格式:

Unfortunately, the previous mouse reporting modes can only handle coordinates up to 223 (255 - 32), or in some situations 95 (127 - 32). So there are some new switches to change the format in which mouse coordinates are reported:

  • 1006 -> 报告为十进制值(xterm,许多其他终端模拟器,但不是 urxvt)
  • 1015 -> 报告为十进制值(urxvt、xterm、其他终端模拟器,一些应用程序发现解析起来很复杂)
  • 1005 -> 报告返回编码为 utf-8(xterm、urxvt,以多种方式损坏)

应用程序的一个好策略是启用鼠标报告,然后(可选地请求 urxvt 1015 模式,然后)请求 SGR 1006 模式.应用程序应处理新的和旧的鼠标报告响应,以在不支持新模式的情况下继续使用终端模拟器.

A good strategy for an application would be to enable mouse reporting, then (optionally request urxvt 1015 mode and then) request SGR 1006 mode. The application should handle both the new and legacy mouse reporting responses, to continue working on terminal emulators without support for the new modes.

有关新报告模式的更多信息,请访问:

More information on the new reporting modes at:

这篇关于如何在 bash 中获得 MouseMove 和 MouseClick?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆