How to run the same function that is already running?

local function keyPress(info)
   -- function code here

Then instead of putting the function after connect, put keyPress

Instead of writing the function for A, just write a bit that detects if A or B has been hit, and if it has, run the function.