Here's a sample celx script that creates a keyboard handler:
Code: Select all
-- A sample keyboard handling function
function showmessage()
celestia:flash("Key pressed")
end
-- The table mapping key names to handlers
keyhandlers =
{
p = showmessage,
q = showmessage,
}
function handlekey(k)
-- k is a table containing the event properties; in this simple sample,
-- we're only interested in char, the name of the key that was pressed.
handler = keyhandlers[k.char]
if (handler ~= nil) then
handler()
return true
else
return false
end
end
This sample binds the keys p and q to the handler showmessage(). The bindings will remain until either Celestia is restarted or another script is run to unbind them.
Here's a useful little handler function that I wrote to toggle cloud shadows on and off, because switching them on and off is not yet built into Celestia.
Code: Select all
function togglecloudshadows()
t = celestia:getrenderflags()
celestia:setrenderflags{cloudshadows = not t.cloudshadows}
end
There are also mouseup, mousedown, and tick events. I'll post more information about them soon.
--Chris