title: Mouse events in terminal emulator
body: <p><strong>Question</strong></p>
  
  <p>Is it possible, in a terminal emulator, to run a command whenever a mosue event happens?</p>
  
  <p><strong>What I've tried</strong></p>
  
  <p>I think I'm halfway there - using <code>echo -e "\e[?1003h"</code> (see <a href="https://stackoverflow.com/questions/5966903/how-to-get-mousemove-and-mouseclick-in-bash">here</a> 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. (Note: <code>echo -e "\e[?1003l"</code> turns this off)</p>
  
  <pre><code>echo -e "\e[?1003h"
  # move mouse over terminal window, in the character input line, NOT to stdout:
  &gt; CF*CC+C@,C;.C:/C8/C8/C8/C8/C9/C9/C9/C90C90C80C81C81C81C81C81C90C:/C;/C;.C&lt;.C&lt;.
  
  # After deleting that, I enter:
  &gt; echo -e "\e[?1003l"
  # mouse move, all is quiet
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>&gt; echo -e "\e[?1003h" &gt;&gt; file.txt 
  # elevator music whilst I move the mouse about
  
  &gt; echo -e "\e[?1003l"
  # move mouse a bit, nothing
  
  &gt; cat file.txt
  
  
  # nothing but blank lines, fair enough. But, mouse moves and in the terminal input is printed...
  
  &gt; CF*CC+C@,C;.C:/C8/C8/C8/C8/C9/C9/C9/C90C90C8 ...
  
  #  Delete that output, and then I type:
  &gt; echo -e "\e[?1003l"
  # mouse moves, no output
  </code></pre>
  
  <p><strong>What I want</strong></p>
  
  <p>How can I either capture this output so that it is going to <code>stdout</code>, or to a file, so that I can then use the changing output to trigger running a command? 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?    </p>