First, I would like to know why you have this in the code:
asm("swi");
Next, I would recommend you remove the scan keypad code from main, and use the ScanKeyPad() function from the original sample code, and in the section marked "Application specific code " you call a function that you write take the key code as an argument to execute your menu. In your main function, in your for(; loop, you would call ScanKeyPad() and it would take of the rest.
As I said you will call a function of your own design from ScanKeyPad() every time a new key is detected. In this function you will have a variable that keeps track of the current state - it would start off as say state 0, which means "top" menu. When you are in this state 0, you will decode the key to mean a menu function is being selected - if it is an "A" you will move the state to 1, which means I am in menu state "A". Now when a key is pressed, you will do what menu function "A" would do with a key press. In state 0 you might simple ignore keys that are not valid menu items.
Then there would be some way that the use ends menu state "A". For example pressing "#" ends menu function "A" and does something with the entered data and returns to the orginal state, "top" menu state 0 as I mentioned.
When in state 0, pressing a 'B' would go to state 2 and so on.
So this function that is called from ScanKeyPad will first examine the current state then decide what to do with the key. It would not be a bad idea to have a separate function for each menu function. For example you might have a function called "byte MenuA( byte keycode)" that is called when in state 1. You would take the return value to determine the next state, so that when menu function A determines that it is done, it signals that it is time to return to state 0.
Consider what I have said. If it is not clear please ask further.