When I leave my computer unattended in the office I usually lock the screen. Usually going to the login window or screen saver requires the mouse. Here I show how you can set a keyboard shortcut that will lock your screen and login window. I tested this on OS X 10.7, but it probably works in other versions as well.
1. Open Automator and create a new Service. Set the service to receive no input and to be launched in any application. As an action add Run Shell Script and enter the following line:
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
Save your new service.
2. Now go to System Preferences > Keyboard > Keyboard Shortcuts. In the menu on the left select Services and scroll to the bottom to find your new service. You can now assign your keyboard shortcut of choice.
The shortcut will take you to the Login Window from any application supporting services (i.e. most applications).
If you prefer to use the mouse, there are several alternatives. You can enable fast user switching in Users & Groups Preferences to get an item for login window in the menu bar, you can use the Keychain Access menu bar icon, or you use a hot corner to activate a screen saver.

