Type Function Object InputDevice Return value none Revision Release 2024.3703 Keywords device, input, vibrate, canVibrate See also object.canVibrate
Causes the input device to vibrate/rumble.
This is a feature that is typically only supported by gamepads. You can determine if the input device supports vibration feedback by reading its canVibrate property.
On Android, you must add the following permission to the build.settings
file.
settings = { android = { usesPermissions = { "android.permission.VIBRATE", }, }, }
-- Called when a key event has been received local function onKeyEvent( event ) -- Vibrate the gamepad if its 'A' button was pressed if ( event.keyName == "buttonA" ) and ( event.phase == "down" ) then if event.device and event.device.canVibrate then event.device:vibrate() end end end -- Set up the above function to receive key events Runtime:addEventListener( "key", onKeyEvent )