Please take each of the following steps until the problem is resolved. With a desktop Mac, you may need to use a USB keyboard or mouse. You should always have one of each available as a spare.
Step 1
Follow the instructions on the applicable pages linked below:
How to set up your Apple Wireless Keyboard
How to set up your Apple Wireless Mouse or Magic Trackpad
Step 2
Reset the System Management Controller.
Step 3
Back up all data.
Triple-click anywhere in the line below on this page to select it:
/Library/Preferences/com.apple.Bluetooth.plist
Right-click or
control
-click the line and select
Services ▹ Reveal
from the contextual menu.* A folder should open with an item selected. Move the selected item to the Trash. You may be prompted for your administrator login password. Reboot.
*If you don't see the contextual menu item, copy the selected text to the Clipboard (command-C). In the Finder, select
Go ▹ Go to Folder...
from the menu bar, paste into the box that opens (command-V). You won't see what you pasted because a line break is included. Press return.