You can use parallel or use a loop that filters by event type, for example…
Using a loop…
while true do --# start and infinite loop
local event, data, mX, mY = os.pullEvent() --# capture events
if event == "mouse_click" then --# if the event is a mouse click then...
--# do mouse event stuff, data = mouse button, mX & mY = mouse x & y position
elseif event == "char" and data:lower() == "q" then --# if the letter 'q' is pressed...
return --# return from the loop, thus exiting it
elseif event == "reactorUpdate" then --# if the event is a reactor update or whatever then...
--# do screen update stuff
end
end
Using parallel…
local function inputMouse()
while true do --# start an infinite loop that never exits
local _, mButton, mX, mY = os.pullEvent("mouse_click") --# capture mouse click events
--# do mouse click stuff here
end
end
local function inputChar()
while true do --# start in an infinite loop that never exits
local _, char = os.pullEvent("char") --# capture character events
if char:lower() == "q" then return end --# if 'q' is pressed, 'return' from this function, thus exiting it and allowing the program to exit
end
end
local function reactorUpdate()
while true do --# start an infinite loop that never exits
local _, data1, data2, data3 = os.pullEvent("reactorUpdate") --# capture reactor update events
--# do screen update stuff here
end
end
parallel.waitForAny(inputMouse, inputChar, reactorUpdate) --# parallel.waitForAny allows all functions to run together, it will terminate when any function exits