CMCC Screen and Mouse Variables
If the CM Control Center (CMCC) is running on your system, the CMS files
have access to 4 additional predefined variables. These are SCREENWIDTH,
SCREENHEIGHT, SCREENX, and SCREENY. These give the CMS files access to
the screen size and mouse position while the script is running. If the CMCC
is not active, then these variables return values of zero.
SCREENWIDTH and SCREENHEIGHT
SCREENWIDTH and SCREENHEIGHT are read-only variables and contain the
screen resolution that's currently in effect on the system. For example,
if your system is currently set to provide a display resolution of
1024 x 768, then referencing SCREENWIDTH will return 1024 and SCREENHEIGHT
will return 768. These are primarily useful when used with the SCREENX
and SCREENY variables described below.
SCREENX and SCREENY
The SCREENX and SCREENY variables are read/write variables that are used
to get or to set the current mouse cursor position directly. The values
are in terms of screen pixel coordinates and follow the Windows convention
that put the 0,0 point in the top/left corner of the screen. The maximum
position will be one less than the screen resolution for both X and Y. If
the current screen resolution is 1024 x 768, then valid mouse positions
are X values from 0 to 1023 and Y values from 0 to 767. If you read the
SCREENX and SCREENY variables, you will get the current mouse cursor
position. If you write the SCREENX and SCREENY variables, the mouse cursor
will "jump" to the position that the values indicate.
A Note on the Mouse Buttons
While it's surprisingly easy to obtain the mouse cursor information,
registering left or right clicks from the regular system mouse is virtually
impossible to do reliably. Consequently, system mouse clicks are not
available. You can still program any of the buttons on your CH controllers to
send a mouse click or activate the DX Mode Mouse Button 1 or Mouse Button 2
functions and send the clicks, the limitation is only in getting the clicks
from the real mouse.
A Note of Caution
As mentioned earlier, these variables are all zeroed if the CMCC is not
running. This can create problems, especially if you pass your map along
to others who don't normally use the CMCC. You should check at the beginning
of the script to see if the variables are active and take steps to ensure
that things don't get out of hand if they're not, and you should test the
map without the CMCC running to be sure you know what's going to happen.
Nothing really "disastrous" will happen, probably the most common thing
is likely to be that the mouse will "stick" in one of the screen corners
as soon as you activate the map. The only way out of this situation is to
unplug a controller, that will put the CM back to Direct Mode and the
script will stop running.
Some Possible Uses
There are a number of possible uses for these variable. These are just a
couple of ideas of things that might be useful.
Function Activation
Many games and simulations provide onscreen toggle switches, etc. that
can be clicked by the mouse. You can set a button to move the cursor
to that position by setting SCREENX and SCREENY, then generate a mouse
click when it gets there, effectively providing a single-button activation
of that function.
Along those same lines, you can add mouse activation of virtually any
function in a game even if the game doesn't provide the function by
setting aside some area of the screen to be used as the "active area"
for the function, then having the script watch for a mouse click. When
the button clicks, you would check the SCREENX and SCREENY position, and if
it's in the proper range having it activate a button or send a character
to cause the function to operate.
For example, suppose your sim provides an indicator on the panel that
shows whether the landing gear is up or down. If you define a rectangle
around the indicator, you can check to see if the mouse cursor is in the
area bounded by the rectangle by reading the SCREENX and SCREENY values.
If it is, then you can have the script actuate a button to send the
command to toggle the gear, so putting the cursor on the landing gear
indicator and clicking the button toggles the landing gear. Not useful
for a single function, but if there were several functions on the screen
it could save a lot of buttons since a single button could send one of
many different functions depending on the mouse position.
Mouse Position Setting Directly
Setting the SCREENX and SCREENY locations results in a nearly
instantaneous movement of the mouse cursor to the new position. This
could be very useful in situations that required precise mouse control.
A sequence could easily be set up to send a series of precise mouse
positioning commands with some fairly exact timing between them.
A Simple Demo
This is a simple demo script that uses all four functions and can be set
up pretty quickly. It basically turns your system mouse into a "joystick".
First, start a new map. Add a controller of some sort and then add the
CMS Controls. Clear the X and Y axes on the stick to NONE and NONE, then
assign CMS.A1 and CMS.A2 to CM Device 1, X and Y, respectively. Finally,
create the following script using the CM Editor:
SCRIPT
CMS.A1 = (SCREENX * 256) / SCREENWIDTH;
CMS.A2 = (SCREENY * 256) / SCREENHEIGHT;
ENDSCRIPT
Download the script and then look at the created Control Manager Device
using the GUI test screen (make sure the CMCC is running). The X/Y
display should track your regular mouse position, hitting the top, bottom,
and sides of the X/Y display box in the calibration screen just as the
mouse cursor hits the top, bottom, and sides of the system display screen.