Your title says “while” and body says “every time the button is pressed”, so it’s not 100% clear which you mean.
Simplest approach would be be to just toggle a function’s listener on or off depending on whether a desired key is held down or not and then adjust the direction based on what key was last pressed. Something along these lines:
local value, change = 1000 local function updateValue() value = value + change print( value ) end local function onKeyEvent( event ) if event.keyName == "down" then if event.phase == "down" then change = -1 Runtime:addEventListener( "enterFrame", updateValue ) else Runtime:removeEventListener( "enterFrame", updateValue ) end elseif event.keyName == "up" then if event.phase == "down" then change = 1 Runtime:addEventListener( "enterFrame", updateValue ) else Runtime:removeEventListener( "enterFrame", updateValue ) end end return false end Runtime:addEventListener( "key", onKeyEvent )