You first need to use a variable to differentiate when it can freely move and not. Then when it's set to not freely moving, there are several ways to do it. My approach would be while in this state pressing A subtracts 1 from a variable and D adds 1 to a variable, that can be of possible values 0,1,2 or 3 and each number corresponds to an on screen button, when var=0 it is on the first button for example.