KnowledgeBase 00112: Using the Mouse in Character Mode Applications

The image presented by established character mode applications can often be
improved by adding features more commonly related to GUI applications such as
the ability to use the mouse to click on items displayed to the user. This
article describes how an application using AccuTerm terminal types with the -at
suffix, QMConsole on Windows, the deprecated QMTerm or QM installed on a PDA
can detect and process mouse clicks.

Enabling the Mouse

Mouse click detection is disabled by default. The QMBasic MOUSE statement can
be used to enable this

MOUSE ON

This action sends a control code to the terminal emulator asking it to pass
mouse click information to the server.

Detecting a Mouse Click

The code sent to the server is different depending on the terminal emulator in
use. The QMBasic KEYCODE() and KEYCODEV() functions use the terminfo
definitions to parse the incoming code into a common form, returning a value of
char(K$MOUSE) or KV$MOUSE respectively if a mouse click is detected.

Additional data relating to the mouse click is stored in three system
variables, @MBUTTON, @MROW and @MCOL and can be used by the application to
determine which button was pressed and where the mouse was positioned on the
screen.

the @MBUTTON variable is set to 1 for the left button, 2 for the right button
and 4 for the centre button. Pressing multiple buttons simultaneously forms
an additive value from the individual button numbers.
Some terminal types can only return mouse clicks for the left button.

The @MROW and @MCOL variables are set to the row and column positions,
numbered from zero in the same way as cursor positions.

Example

The following example shows how an application can recognise multibyte control
key sequences and mouse clicks in a common code path.

Beyond the Mouse

The mouse click detection method described above is adequate for many uses.
The SUI (Smart User Interface) of AccuTerm provides a great way to introduce
additional GUI features into a character mode application without needing to
rewrite the user interface.