Here is a good tutorial which will help you to create a short cut keys to lock your mac machine
http://www.macyourself.com/2013/01/27/how-to-lock-your-mac-screen-with-a-keyboard-shortcut/
Lock Screen Service
1. Launch Automator from your Applications folder.
2. Select Service as the document type.
3. Select Utilities from the list on the left, then double-click Run Shell Script in the next column.
4. On the top-right side of the screen, adjust the drop-down menus so the statement reads: Service receives [no input] in [any application]
5. Copy the following command into the large text box that appears:
/System/Library/CoreServices/"Menu Extras"/User.menu/Contents/Resources/CGSession -suspend
6. Go to File > Save and name your service Lock Screen. Once saved, you can now quit Automator.
Lock Screen Keyboard Shortcut
1. Launch System Preferences and go to the Keyboard pane.
2. Next, select the Keyboard Shortcuts tab. From the list on the left, select Application Shortcuts. Click on the plus (+) button below to add your new shortcut.
3. In the dialog box we’ll want to leave All Applications selected in the first menu. Enter Lock Screen as the Menu Title. Please note this has to be exactly the same name you entered when saving the service in Automator. Finally, enter your keyboard shortcut. Let’s go with Command+Option+Shift+L.
4. Click Add and you’re all done!
Now when you press your keyboard shortcut (Command+Option+Shift+L), the Mac login screen will immediately be displayed. You’re still technically logged in and processes such as large downloads will continue in the background. But you can leave your Mac unattended without worry – no one will be able to access your account until you enter your password. When you do, everything on your desktop will be there just as you left it!