How to simulate a specific key on mobile

On Roblox, there are items that can be activated using a specific key on the keyboard and I’m trying to figure out how to add this feature to mobile devices. Which in my case i want to add the F key, so far I’ve seen what some people using this kind of script:

local userInputService = game: GetService("UserInputService")

-- Simulate a key press
function simulateKeyPress(keyCode)
    userInputService:SetKeyDown(Enum.KeyCode[keyCode])
    wait(0.1) -- Adjust the delay if needed
    userInputService:SetKeyUp(Enum.KeyCode[keyCode])
end

-- Example usage: Simulate pressing the 'F' key
simulateKeyPress("F")

I’m guessing this works, but I want to make sure. I want to add it to a button so mobile plays can press it and will activate its ability kinda like an attack in the Strongest BattleGrounds. Plus I don’t know anything about scripting.