Mouse Events
Overview
Mouse events in CC: Computer Energetics and CC:Tweaked are used to detect and respond to user interaction with the computer's screen or attached peripherals such as monitors. These events are generated by the system when a mouse button is pressed or released, or when the cursor moves over the screen area.
Calling Conventions / Prefixes
Mouse events are standard operating system event types handled via os.pullEvent() or os.queueEvent(). They do not require any prefix like cee.:
local _, x, y, button, down = os.pullEvent("mouse")
API Reference Table
| Method Signature | Arguments & Types | Description |
|---|---|---|
os.pullEvent("mouse") |
None | Waits for a mouse event and returns the event data. |
os.queueEvent("mouse", x, y, button, down) |
x (number), y (number), button (number), down (boolean) |
Queues a mouse event for later processing. |
Lua Code Examples
Example 1: Basic Mouse Input Detection
while true do
local _, x, y, button, down = os.pullEvent("mouse")
if down then
print("Pressed at:", x, y, "button:", button)
else
print("Released at:", x, y, "button:", button)
end
end
Example 2: Click Detection on a Grid
local function handleGridClick()
while true do
local _, x, y, button, down = os.pullEvent("mouse")
if down and button == 1 then
local cellX = math.floor((x - 1) / 5) + 1
local cellY = math.floor((y - 1) / 5) + 1
print("Clicked on grid cell:", cellX, cellY)
end
end
end
handleGridClick()