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

查看:363
本文介绍了如何在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终端仿真器定义了一些控制序列来进行鼠标跟踪,您可以在鼠标跟踪在xterm发行版的 ctlseqs 中。如果你安装了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 - >所有移动报告,报告所有动作。

  • 9 -> X10 mouse reporting, for compatibility with X10's xterm, reports on button press.
  • 1000 -> X11 mouse reporting, reports on button press and release.
  • 1001 -> highlight reporting, useful for reporting mouse highlights.
  • 1002 -> button movement reporting, reports movement when a button is pressed.
  • 1003 -> all movement reporting, reports all movements.

控制序列是 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"

然后,按钮上会出现一堆字符,请参阅 ctlseqs console_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)的坐标,或者在某些情况下, - 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,其他终端仿真器,一些应用程序发现它很复杂)解析b $ b
  • 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:

  • midnight-commander ticket #2956
  • tmux ticket #26
  • midnight-commander ticket #2662

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

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