How to detect mouse, in Lua?


I was recently able to solve an issue related to controlling screen coordinates in a terminal (thanks to the answer found here on SOpt). Now I need to detect the movements and clicks of a pointing device (mouse). Is it time to think about a graphical toolkit , or is there a simpler alternative?


A solution to detect mouse movements with Lua and in terminal mode would be to use wxLua , which is usually already integrated in some implementations.

Basically you call:

pt = wx.wxGetMousePosition()
io.write(pt.x) -- é a posição em x do ponteiro
io.write(pt.y) -- é a posição em y do ponteiro



-- Loop que vai atualizar o mostrador da posição do mouse:
while true do

    -- wx.wxGetMousePosition() retorna a posição do mouse na tela
    pt = wx.wxGetMousePosition()

    -- atualiza o mostrador:
    io.write("x = " .. pt.x .. "\ny = " .. pt.y .. "\n")
    os.execute("cls") -- ou os.execute("clear") em Unix
Scroll to Top