How to detect the mouse, in Lua?

Asked

Viewed 211 times

4

I recently managed to solve a problem related to the control of screen coordinates in a terminal (thanks to the answer found here in Sopt). Now I need to detect the movements and clicks of a pointing device (mouse). It’s time to think and a Toolkit graphic, or there is some simpler alternative?

  • 1

    The standard Lua library is super simple, and basically only exposes things that come from the standard C library. Just like in the case of terminal coordinates, you’ll have to use some library to mess with the mouse.

  • Thanks hugomg. I’m experiencing the IUP. Regarding the coordinates on the screen, I used this answer [link] http://answall.com/questions/23176/howto control the coordinates of the screen

  • Did you find a solution? Poste as an answer to help other people.

  • I solved my problem using IUP (graphical environment)... But, in fact, I could not solve the problem of the mouse in terminal mode. :(

1 answer

3

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

Basically, you call it:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.