David
David

Reputation: 151

lua mouse event handler

I'd like to create an event handler in lua which can detect and locate mouse clicks (and ideally wheel movements) within a window, but can't find any way of doing it. Is there any way of doing it in lua, or would it be possible to create a hook somehow?

Events don't have to be reacted to immediately, so if there were some way of creating a table of mouse events which could subsequently be read from that would be fine.

I'm on ubuntu 14.04, and have Python available (if that helps). Thanks David

Upvotes: 2

Views: 2559

Answers (1)

jgriego
jgriego

Reputation: 1266

Not sure exactly what your requirements are, but there's a few options.

By far the easiest would be to use would be LOVE -- technically it's a sort of game framework that hosts Lua scripts but it displays a window and you can handle the events inside of the Lua runtime. Code to accomplish this would be roughly:

function love.mousepressed(x, y, button)
  -- do stuff here
end

More difficult but more Lua-centric might be something like wxLua which should allow you to create and manage a native window against the wxWidgets library (N.B. I have never gotten this to compile and run on OS X)

There's a number of bindings like wxLua to other GUI frameworks. There's a complete list over at the lua-users wiki.

Upvotes: 1

Related Questions