From: Chris on
I am using a terminal emulation program that lets the mouse send its x
& y coordinates when one of the buttons is pushed.

For example, using cat -v and executing some simple mouse clicks at row
1, column 1 in the emulator, I get thoe following escape sequences:

^[[M !! (left mouse button)
^[[M"!! ( right mouse button )
^[[M!!! ( middle mouse button )

At row 2, column 1 I get the following:

^[[M !" ( left )
^[[M"!" ( right )
^[[M!!" ( middle )

At row 24, column 1 I get the following:

^[[M !8 ( left )
^[[M"!8 ( right )
^[[M!!8 ( middle )

At row 24, column 80 I get the following:

^[[M t8 (left )
^[[M"t8 ( right )
^[[M!t8 ( middle )

Retrieving the individual values being returned by the escape sequence
is not a problem - I am more concerned with how to translate this to
screen coordinates.

Obviously, any sequence that starts esace (^[), left bracket ([), M
indicates a mouse click. The next position indicates the mouse button
(left ' ', right '"', middle '!') and the next two characters indicate
the actual position on the screen. I can further infer from these
results that the first of the two positional bytes represents column,
and the second byte indicates row.

My question is this - any thought on how to convert the character
values into the actual numeric coordinates?

I would love to make my application "mouse aware," but I need a
reliable way to convert these sequence to numerical coordinates first.
(Conversions have always been a sore spot for me).

Any and all help is greatly appreciated.

Thanks,
Chris

From: Chris on
Ah - as usual, soon after posting out of frustration, I stumbled across
my own answer.

You need to use the decimal values of the coordinates and subtract 32
from them to obtain column and row values.

So - in my examples above:

! = 33 - 32 = 1
" = 34 - 32 = 2
8 = 56 - 32 = 24

Of course - the 't' does not work here ( t = 116 - 32 = 84 ), but that
is because my emulator window was in fact set to 84 columns wide.

With this in mind, I shoul dbe able to make my program "mouse aware".

Has anyone had any experience with this? Any pointers/tips would be
appreciated ...


Thanks again,
Chris

From: robertwessel2@yahoo.com on

Chris wrote:
> Ah - as usual, soon after posting out of frustration, I stumbled across
> my own answer.
>
> You need to use the decimal values of the coordinates and subtract 32
> from them to obtain column and row values.
>
> So - in my examples above:
>
> ! = 33 - 32 = 1
> " = 34 - 32 = 2
> 8 = 56 - 32 = 24
>
> Of course - the 't' does not work here ( t = 116 - 32 = 84 ), but that
> is because my emulator window was in fact set to 84 columns wide.
>
> With this in mind, I shoul dbe able to make my program "mouse aware".
>
> Has anyone had any experience with this? Any pointers/tips would be
> appreciated ...


My suggestion is to go yell at whoever came up with this scheme. It's
some perverse hybrid of ANSI and non-ANSI control sequence syntax. I
mean, for crying out load, attaching this device to a host that doesn't
have specific knowledge of it will cause all sorts of errors. At least
if the device *had* conformed to the usual CSI syntax, any host would
be able to parse the string, and say, I don't know what this is (and
perhaps issue a beep or an error message). Instead, it'll see CSI+M
(which will probably get the beep) plus three characters that it'll
treat as ordinary input.

FWIW, a CSI sequence should be of the form: "CSI P...P I...I F" where
P...P is zero or more parameter bytes in the range 0x30 to 0x3f, I...I
is zero or more intermediate bytes in the range 0x20 to 0x2f, and F is
a final byte terminating the sequence in the range 0x40 to 0x7e (which
is the critical item from a parsing perspective). So typically you'd
expect to see something like "CSI 12;45;2M" to define something like
this (where the three parameters might be row, column, button, and the
M is what terminates the sequence and defines its major meaning. If it
were done right, then a host could ignore/beep the sequence just like
it could ignore/beep a "CSI 123~" from a terminal with a hypothetical
F112 key.

Rant aside, you're probably just going to have to recognize the CSI M
initiator, and then suck in the next three characters. Note that CSI
can be coded as either "Esc [" (0x1b, 0x5b) or, if the terminal is in
eight bit mode, as the single character: 0x9b.

From: Richard on
> I would love to make my application "mouse aware,"

I would suggest that you look at libgpm.

 | 
Pages: 1
Prev: Cobol Compiler
Next: COBOL as CGI