How to detect the mouse, in Lua?

4

I recently solved a problem related to the control of screen coordinates in a terminal (thanks to the response found here in SOpt). Now I need to detect the movements and clicks of a pointing device (mouse). Is it time to think and a graphical toolkit , or is there some simpler alternative?

    
asked by anonymous 19.07.2014 / 04:51

1 answer

3

One solution to detect mouse movements with the moon and in terminal mode would be to use wxLua , which is often integrated into 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

Example

require("wx")

-- 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
end
    
14.11.2014 / 17:41