If I understand the problem correctly, how about whenever the mouse is clicked (resulting in movement), set a variable with the point that was clicked (okay, maybe 2 variables, x and y). Do the same with when the keypad is used, setting a different variable, but with a 'keypad' directional value. Every time you use the keypad for movement, wipe out any saved value in your 'mouse' variable, and the reverse (wipe out your stored 'keypad' variable when the mouse is clicked).
Then you'll be able to use the variables to determine what the last movement was entered with. That would be the input for your missing 'if'.