Mouse and Keyboard Input?

Hello all,

So I know

event.phase == “ended”, “began”, etc… works for when you click an object, but what about things like mouse hover, scrolling, right click?

Same deal with keyboard. Can we detect keystrokes like “activate this ability by pressing the ‘2’ key”, “jump with ‘spacebar’”?

Sorry if I missed documentation on this.

Cheers!

Yes, we support both “key” events and “mouse” events on Windows.  Have a look here…

   https://docs.coronalabs.com/api/event/key/index.html

   https://docs.coronalabs.com/api/event/mouse/index.html

Ah appoligies. Haven’t hunted through all the new docs yet! Thank you!

Happy to help!  And for bonus points, mouse events are supported on Android too.  We added support for it 2 years ago on Android because Ouya gamepad’s have a mouse trackpad.

And here’s the Lua script that I use to test mouse support…

local mouseCircle = display.newCircle(0, 0, display.contentWidth / 10) mouseCircle:setFillColor(1, 1, 1) mouseCircle.isVisible = false local function onMouseEvent(event) print("Mouse Event: " .. " Position(" .. tostring(event.x) .. "," .. tostring(event.y) .. ") Buttons(" .. tostring(event.isPrimaryButtonDown) .. "," .. tostring(event.isMiddleButtonDown) .. "," .. tostring(event.isSecondaryButtonDown) .. ")") mouseCircle.x = event.x mouseCircle.y = event.y if (event.isPrimaryButtonDown or event.isMiddleButtonDown or event.isSecondaryButtonDown) then mouseCircle:setFillColor(1, 0, 0) else mouseCircle:setFillColor(1, 1, 1) end mouseCircle.isVisible = true end if (system.hasEventSource("mouse")) then Runtime:addEventListener("mouse", onMouseEvent) else print("Mouse events not supported on this platform.") end

Yes, we support both “key” events and “mouse” events on Windows.  Have a look here…

   https://docs.coronalabs.com/api/event/key/index.html

   https://docs.coronalabs.com/api/event/mouse/index.html

Ah appoligies. Haven’t hunted through all the new docs yet! Thank you!

Happy to help!  And for bonus points, mouse events are supported on Android too.  We added support for it 2 years ago on Android because Ouya gamepad’s have a mouse trackpad.

And here’s the Lua script that I use to test mouse support…

local mouseCircle = display.newCircle(0, 0, display.contentWidth / 10) mouseCircle:setFillColor(1, 1, 1) mouseCircle.isVisible = false local function onMouseEvent(event) print("Mouse Event: " .. " Position(" .. tostring(event.x) .. "," .. tostring(event.y) .. ") Buttons(" .. tostring(event.isPrimaryButtonDown) .. "," .. tostring(event.isMiddleButtonDown) .. "," .. tostring(event.isSecondaryButtonDown) .. ")") mouseCircle.x = event.x mouseCircle.y = event.y if (event.isPrimaryButtonDown or event.isMiddleButtonDown or event.isSecondaryButtonDown) then mouseCircle:setFillColor(1, 0, 0) else mouseCircle:setFillColor(1, 1, 1) end mouseCircle.isVisible = true end if (system.hasEventSource("mouse")) then Runtime:addEventListener("mouse", onMouseEvent) else print("Mouse events not supported on this platform.") end