r/ComputerCraft • u/SeasonApprehensive86 • Jun 23 '24
Mouse release event not firing when it should
I have this simple function for keeping track of the mouse buttons, but when holding down any two buttons and releasing one the one still being held gets stuck like that even after releasing. I have essentially the exact same system for keepting track of the keyboard modifier keys and it works without issues. This function is running in a paralell.waitForAny itself with the main loop and some others.
I need a table where I can get the state of any mouse button I want. So I can just go like if(mouseButtons.LMB)then end. Also is there a mouse hover event?
local mouseButtons = { LMB = false, RMB = false, MMB = false, };
local function handleMouseInput()
local buttonMap = { [1] = "LMB", [2] = "RMB", [3] = "MMB", };
local function mouseDown()
while (true) do
local _, button, x, y = os.pullEvent("mouse_click");
mouseButtons[buttonMap[button]] = true;
end
end
local function mouseUp()
while (true) do
local _, button, x, y = os.pullEvent("mouse_up");
mouseButtons[buttonMap[button]] = false;
end
end
parallel.waitForAny(mouseDown, mouseUp);
end
4
u/fatboychummy Jun 23 '24
I meant to reply earlier, but got busy.
I don't see anything explicitly wrong with your code here. My only thought is that I'm unsure how CC:T handles if you click then drag off-screen before releasing. Or is it happening when you just click and release on-screen?
What version of CC:T/MC are you running?
As for a mouse hover event; No, with exception of the emulator
CraftOS-PC. CraftOS-PC has a toggleablemouse_hoverevent, but CC:T itself does not. Reasoning is that multiple players can use a computer at a time, so you'd need a way to determine which user was hovering where.1
u/GROOOOOOD Jun 23 '24
os.pullevent makes the program wait until the event happens. So your program runs both in paralel but stops on one of the pullevents