To lock and unlock a keyboard on a Mac laptop, click on System Preferences inside the Apple menu, and then click on Security & Privacy. Inside the General tab, click on Require Password after Sleep or Screen Saver Begins. Select Immediately in the drop-down box for the tightest security.
Users who want additional security can click on Disable Automatic Log-In; the keyboard then locks when put to sleep. To put a computer into sleep mode, select Sleep from the Apple menu. To awaken a computer from sleep mode, enter the password. The password unlocks both the computer and the keyboard.