If you’re having a problem with GNOME, it’s easy to restart it from a terminal. A common issue you can fix is playing a 3D game that crashes and locks the mouse and keyboard.
In Ubuntu and many other distributions you can use this command to restart the GNOME display manager:
sudo /etc/init.d/gdm restart
You can also simply start or stop it:
sudo /etc/init.d/gdm start sudo /etc/init.d/gdm stop
Stopping GDM causes GNOME and all graphical applications to quit, starting it will take you to the login screen.
If you can’t even get to a terminal, you may be able to over SSH from another computer. I’ve had to do this once or twice when the keyboard was not responding at all, and restarting GDM fixed it.