![]() |
The Special Objects - The Mouse and Keyboard | ![]() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The mouseKeyboard object controls the mouse pointer, and the keyboard. It can be used to monitor and control user inputs.
The base of the examples in this section is as follows:
The counter's value will increase when the condition is true. Let's take a look at some functions then: The simplest check is "MouseClick". Replace the If( TRUE ) line with the following:
If you run this, every time you click anywhere in the window, the counter will rise. Note that double clicks do count as 2 clicks in JAM, as well as a double click (see below) Let's refine it a bit; using zones. There are two parts to using zones, firstly we must set one up, then we must check if the user has clicked in it. In the Startup1 function, add the following line (it doesn't matter where):
We now have a zone set up from 0,0 to 400,300. Now we want to check if the user clicks in it. Replace the If condition again with this:
And the counter will only increment if the click is within the zone. Alternativley, you can provide the details of the zone directly in the MouseClickInZone event, but creating a JAMzone is recomended, as it allows easy re-use and modification. The final Click event is MouseClickOnObject. To demonstrate this, we will now make the counter only increment if it is clicked on. You can remove the zone creation from the startup code now, and replace the If condition with this:
That's all there is to it. If you want, you can also use fine detection:
(counters do not currently support fine detection, so you will see no change. However, active objects do support fine detection.) If you take out the "Click" from any of these functions, they will be TRUE when the mouse is over the given object/zone. If you add Rep to the end of any of the functions, they will continue to be TRUE while the button is down. You can also provide an extra parameter for the button:
Window.MIDDLEBUTTON is also supported. Still with the mouse, it's position, visibility and shape can all be compared and changed... To find it's position is very simple. Replace both events in Code1 to be the following:
and the counter will always set to the X of the mouse. Also, the position of the mouse in the window and screen can be retreived:
What's the difference between GetXMouse and GetWindowXMouse? GetXMouse is the mouse position on your frame, including scrolling, scaling, etc. GetWindowXMouse is the raw position of the mouse relative to the window's top left corner. You can change the position of the mouse too:
Here I have added a safety check - the mouse will only move when you click the left button. You may still need to use Alt+F4 to exit though. SetWindowMousePos can also be used to set both X and Y positions at the same time. SetScreenXMouse, etc. are also supported, and so are SetXMouse, etc. To be finished... JAM © 2005 no one in particular Project started by David Evans in 2005 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||