How do you get a key press from a text box (Example: Enter)?

How would you get the last URL from a string (like clicking back button) same goes for forward.

Any help appreciated.