A mouse module for LÖVR.
Copy lovr-mouse.lua to your project and require it. I like to put it on the lovr global like this:
lovr.mouse = require 'lovr-mouse'
function lovr.update(dt)
print(lovr.mouse.getPosition())
endlovr-mouse can only run on systems where LÖVR uses both LuaJIT and GLFW. If your project needs to be compatible with Android or WebVR, you can optionally include lovr-mouse with:
if type(jit) == 'table' and lovr.system.getOS() ~= 'Android' and lovr.system.getOS() ~= 'Web' then
lovr.mouse = require 'lovr-mouse'
endNote that lovr.mouse.setRelativeMode will conflict with the mouselook behavior of the VR simulator. To fix it, add this to conf.lua to disable the headset module:
function lovr.conf(t)
t.modules.headset = false
endmouse.getX()Returns the x position of the cursor.mouse.getY()Returns the y position of the cursor.mouse.getPosition()Returns the x and y position of the cursor.mouse.setX(x)Sets the x position of the cursor.mouse.setY(y)Sets the y position of the cursor.mouse.setPosition(x, y)Sets the position of the cursor.mouse.isDown(button, ...)Returns whether any of the specified buttons are currently pressed. Available buttons:1the left mouse button.2the right mouse button.3the middle mouse button.- Other higher numbers may be supported for fancier mice.
mouse.setRelativeMode(enable)Sets or disables relative mode. In relative mode the cursor is hidden and it can move infinitely (you can use the dx and dy parameters of mousemoved to get the movement amounts).mouse.getRelativeMode()Returns whether relative mode is currently enabled.mouse.getSystemCursor(systemCursorKind)Returns a Cursor UserData pointer which is GCed, so keep it in scope as long as you want to use it. Available Cursor kinds:arrowYour regular system cursor. The pointy one.ibeamI style cursor. You see this kind when you hover over text.crosshairThe + cursor.handThe hand, usually with the pointer finger raised.sizeweYou see this cursor when you resize a window horizontally.sizensYou see this cursor when you resize a window vertically.
mouse.newCursor(string | blob | image, hotx, hoty)Returns a Cursor UserData pointer which is GCed, so keep it in scope as long as you want to use it.hotxandhotydefine the cursor's "hot spot" (where the little click pixel is).mouse.setCursor(cursor)Sets the cursor. This is the Cursor UserData pointer returned from thenewCursorandgetSystemCursorfunctions. If the Cursor that you set gets GCed, it will reset back to the default Cursor automatically.lovr.mousepressed(x, y, button)Called when a mouse button is pressed.lovr.mousereleased(x, y, button)Called when a mouse button is released.lovr.mousemoved(x, y, dx, dy)Called when the mouse is moved. The arguments represent the new cursor position as well as the delta from the previous position, in window coordinates.lovr.wheelmoved(dx, dy)Called when the mouse is scrolled.
MIT