there is nothing wrong with that, there is no better way.

i mean you call the function if 'a' is pressed, but put an endless loop into that function is a bit more senseless