We have some (possibly undocumented) stuff that was added to support the Shade UI:
-- Mouse/trackpad was moved (no button held down)
function hover(gesture)
end
-- Mouse/trackpad was scrolled (i.e. 2 finger scroll gesture)
function scroll(gesture)
end
Where gesture has the following stuff (ignore the binding code):
LuaBinding(L)
.beginClass<Gesture>("gesture")
.addPropertyReadOnly("location", &Gesture::getLocation)
.addPropertyReadOnly("translation", &Gesture::getTranslation)
.addPropertyReadOnly("delta", &Gesture::getDeltaTranslation)
.addPropertyReadOnly("touchCount", &Gesture::getNumberOfTouches)
.addPropertyReadOnly("state", &Gesture::getState)
.addPropertyReadOnly("shift", &Gesture::shiftEnabled)
.addPropertyReadOnly("capsLock", &Gesture::capsLockEnabled)
.addPropertyReadOnly("alt", &Gesture::altEnabled)
.addPropertyReadOnly("control", &Gesture::controlEnabled)
.addPropertyReadOnly("command", &Gesture::commandEnabled)
.addPropertyReadOnly("numPad", &Gesture::numPadEnabled)
.endClass();
With location
, translation
, delta
all being vec2
types and state
using the obligatory BEGAN
, MOVING
, ENDED
, CANCELLED
constants.
The alt
, control
, etc. are just booleans indicating if those keys were held during the gesture.
Since iOS 14 supports proper access to mouse stuff it might be worth adding an API for it. Maybe it would look like this?
local mouse = input.mouse
-- or mouse = input.mice[1]
mouse.buttonChanged = function(mouse, button, isPressed)
print("Pressed mouse button:", button)
end
mouse.moved = function(mouse, position, delta)
end
mouse.leftButton
mouse.middleButton
mouse.rightButton
mouse.auxiliaryButtons[1]
mouse:capture()
mouse:release() -- not sure if an API for this exists yet
Codea 4 (our new Metal runtime built from the ground up) will have support for keyboard callbacks as global functions, but could also be done similar to the mouse if we use GCKeyboard.
I also want to have support for gamepads, so we can use PS4, Xbox, etc… controllers.