Mouse events

See also: http://www.shatters.net/forum/viewtopic.php?f=9&t=16212

Content

General

Under construction

There are two celx mouse events: mouse down and mouse up. A consecutive mouse down and -up with the same mouse button on the same spot form what we know as a mouse click. As such the celx mouse events are rather useless; their event messages only have these three fields:

  • message.button - the button that was pressed
  • message.x - the x or horizontal coordinate of the "clicked" point on the screen
  • message.y - the y or vertical coordinate of the "clicked" point on the screen

Button is a numeric field; the explanation of the numbers is:

1 = the Left button

2 = the Middle button

4 = the Right button

All other numbers define other buttons and it is possibly dependent on mouse make and/or type which buttons those are. I personally own a contemporary Logitech mouse with two extra buttons, but they won't even yield an event, let alone be that I can see what numbers celx would use to represent them.

The point on the screen where the event happened is typically described by x- and y-coordinate pairs, with the x-coordinates increasing to the right and the y-coordinates increasing from top to bottom. The location of the origin is the upper-left corner of the window.

With this the celx events only tell you with which button the event happened and on what point on the screen; they do not tell you what celestial object - start, planet, moon, spacecraft - the mouse was on when the event happened. And since there does not seem to be any other possibility in celx to correlate a screen coordinate with a celestial object, a mouse event does not really tell you anything useful. You can tell Celestia to ignore the event, but when is that useful when you don't know the context in which the event happened? Add this to it's incompatibility with the wait() function and you are not left with much. If you still really want to try to bend the mouse events to your will, it takes quite a bit of code, to get something done. If you are curious then have a look at the code that comprises: downloads/custom types/mouse types.

If you intercept the "mousedown" event type and do not see on the screen what you might expect, then that's possibly because Celestia itself does not react to mouse downs or mouse clicks but to the single mouseup event.

Example

--[[ Function: mouseDownEvent()
------------------------------------------------------------------------
   the mouse down event handler
------------------------------------------------------------------------]]
function mouseDownEvent(eventInfo)

if eventInfo.x < 20 and eventInfo.y < 20 then

        if intercept == false then
            intercept = true
            celestia:print("Started mouse interception\nclick upper left to stop", 2)
            return true
        else
            intercept = false
            celestia:print("Stopped mouse interception\nclick upper left to start again", 2)
            return false
        end
    elseif intercept == true then
        celestia:print("Button: " ..eventInfo.button .." on point (" ..tostring(eventInfo.x) .."," ..tostring(eventInfo.y) ..")")
        return true
    else
        return false
    end
end
--[[ Function: mouseUpEvent()
------------------------------------------------------------------------
   the mouse up event handler
------------------------------------------------------------------------]]
function mouseUpEvent(eventInfo)
    return intercept
end
--[[ Function: Main()
------------------------------------------------------------------------
   the function Main
------------------------------------------------------------------------]]
function Main()
    intercept = false
    celestia:registereventhandler("mousedown", mouseDownEvent)
    celestia:registereventhandler("mouseup", mouseUpEvent)
    celestia:print("Mouse test is active\nclick upper left corner to start intercepting mouse events", 4)
end
--[[ Script
------------------------------------------------------------------------
   start
------------------------------------------------------------------------]]
Main()

Downloads

See also: downloads / custom types / mouse types