Some wireless keyboards come with small dongle connectors. Some can only be set up via Bluetooth, a short-range wireless protocol that couples devices together. To set up a Bluetooth keyboard or mouse, you need to pair it with your Mac. If you set up another Bluetooth device, such as Bluetooth headphones, the setup is pretty much the same.
If you have an iMac and your Bluetooth keyboard is not set by default, or your trackpad and keyboard are on it If you're using a Macbook, you'll need a wired keyboard or mouse to set up a Bluetooth keyboard because you can not without being able to set up an input device. If you only have a keyboard, you can still set up a Bluetooth mouse by using the Tab key in System Preferences to switch between options.
First, you need to make sure Bluetooth is turned on on your computer Mac and your wireless device have charged batteries.
Pair Your Device
Open your Bluetooth settings from the drop-down menu in the top-right corner of the menu bar, or locate it in Spotlight (Command + Spacebar) or System Preferences
have to activate the pairing mode on the keyboard and the mouse. This mode is probably enabled by default if the device is not paired with anything. However, there may be a synchronization button on the back or bottom. For some devices, you may even need to press the power button a few times.
If the device can be detected, it will appear in the list of devices on your Mac with the "Pair" or "Connect" button next to it. 
After you click the button, your Mac may prompt you to enter a pairing code on the keyboard. For other devices, you can usually click past this window, and the device will still pair.
Configuring keyboard and mouse settings
If your keyboard or mouse does not behave properly, you will be able to configure the settings in System Preferences. Under "Keyboard", you can adjust the settings for the key repeat and the function keys or change the keyboard layout. You can also pair a Bluetooth keyboard from here automatically.
Under "Mouse" you can set the tracking speed, double-click speed and scroll speed of your mouse.
For Both Keyboards For mice, the manufacturer may have their own drivers and preference apps to configure device-specific settings such as DPI, macros, and lighting effects, especially in "gaming" mice. These include, for example, the Logitech Control Center, Corsair iCue and Razer Synapse.
Picture credits: Peter Kotoff / ShutterStock