Introduction: Add Bluetooth Keyboard to Rpi2 Kali

About: Exploring, searching, hacking... is my life. I am working on radiation, high voltage, programming, 3d drawing, hacking, music and...

Hello. A long time ago i made "HacKErBox K.E" based on Raspberry Pi 2. Now i will show how to add a bluetooth dongle and how to pair a bluetooth keyboard to Raspberry Pi 2. Remember, this instructable is suitable for Kali Linux 1.1.0 Raspberry Pi 2 distro. For raspbian you can search and find other instructables. Also this instructables is not for Kali Linux 2. Because repositories have changed and bluez interface and commands are different.

-Also i will show how to remap keys on linux if you have a keyboard without ctrl, alt... buttons.

Note: This work was made without any citation. My english is not so good. So please excuse me.

Lets start.

For this project i am using 3 things:

1.Raspberry pi 2

2.Bluetooth Keyboard For Android.

3.CSR (Cambridge Silicon Radio) 4.0

Informations (For making things understandable for everybody.):

Italic parts are codes or file contents.

SOF means Start of file.

EOF means End of file.

Step 1: Add Bluetooth Dongle and Keyboard

This dongle is uncompatible with raspberry pi in some ways. When you reboot your system bluetooth dongle will be unusable. Normally you need to unplug it and plug it again. But i have solved this situation with "usb_modeswitch". Most people oblivious about this command. I use nano as editing files. You can use other edit programs.

You will need a SSH connection or cabled keyboard for this work.

First if you haven't done yet, change your repo address with:

nano /etc/apt/sources.list

Have the following entries in your sources.list:


deb moto main non-free contrib
deb-src moto main non-free contrib


Then save your file and exit. Install necessary modules with this command (I suppose your system is up to date):

apt-get install bluez python-gobject

sudo reboot

Now after reboot plug your Bluetooth Dongle and type this:

hcitool dev

When you hit enter you will see something like:

hci0 xx:xx:xx:xx:xx:xx

If not please check your usb connection and type "lsusb".If you see your dongle in output then try again with "hcitool dev". If it doesnt work then your dongle may be uncompatible.

If you see your device in output then put your bluetooth keyboard in pairing mode and type:

hcitool scan

Output must be like this:

Scanning ...
10:08:11:AB:4A:9B Bluetooth Keyboard

We did it! USB dongle can see our keyboard. Now we need to pair them with "sudo bluez-simple-agent devicename keyboardid"

In this case my command is: sudo bluez-simple-agent hci0 10:08:11:AB:4A:9B

You need to change values for yourself.

The output must be like:

Enter PIN Code:

Now press 0 then press enter from your SSH connection or cabled keyboard. Then press 0 and press enter from your bluetooth beyboard.

The pairing is done. Now enter these commands with changing values for your device:

bluez-test-device trusted 10:08:11:AB:4A:9B yes

bluez-test-input connect 10:08:11:AB:4A:9B

Now we connected our bluetooth keyboard. Now test your keyboard with typing something. If it is working you can go to next step, if not and if you can't find your answer then comment it and i will help you.

Step 2: Remap Your Keyboard (Optional)

This step is not necessary if you are okay with your keyboard buttons. Mine doesn't have necessary keys (you can see in pictures) and i changed the keymap. I chose this path because i prefer spending time to what i have then spending money to readymade products.



mkdir bluekey

cd /root/bluekey

dumpkeys > backup.kmap

Now we have keymap backup. If something goes wrong you can type:

sudo loadkeys backup.kmap

Okay. We need to decide which keys must be changed.

Change list for me:

Search button with magnifying glass symbol --> " button.

Home button --> ALT button.

Volume up button with speaker+ icon --> CTRL.

Now type this command and press buttons which you want to change:


From the output i have found my key numbers:

Search Button=217

Home Button=102

Sound+ Button=115

Also "go back" button at bottom left corner is 1. That means this button is working like ESC button.

Now type dumpkeys | head -1 and take note keymaps 0-? from output. It will be needed. Mine is:

keymaps 0-127

Now we need to make a keymap:

nano blue.kmap


keymaps 0-127
keycode 217 = quotedbl
        shift   alt     keycode  217 = Meta_quotedbl
keycode 115 = Control
keycode 102 = Alt


Now let's test this keymap options with loading them:

sudo loadkeys blue.kmap

Now when i type this three buttons they act like CTRL, ALT and quotedouble. But if you reboot your system your keymap will be gone and default keymap will be active. Also you can't use this command at boot sequence. But you can make a bash alias for yourself:

nano ~/bashrc

And add this line above exit 0:

alias bkey='/usr/bin/loadkeys bluekey/blue.kmap'

Then reboot your system. Login again and type bkey command. You will see something like keymap loaded. You need to use this command at every login.

Step 3: Script for Autostart at Boot

We want to use this keyboard without other inputs. So we need to make a script now. This script will start automatically at boot sequence. You need to change values for your need. (You can change file name if you want to):

nano blue


echo "Resetting Bluetooth!"

sleep 4

usb_modeswitch -v 0a12 -p 0001 -R

echo "Pairing Now!"

sleep 2

bluez-test-input connect 10:08:11:AB:4A:9B

hcitool con

sleep 3




-v means vendor id

-p means product id

-R means reset usb

You can find your vendor/product information with lsusb command.

You can change sleep times but not recommended. Because usb reset process need some time. Now let's add our script to boot sequence:

nano /etc/rc.local

And add this line:


Well done!

Step 4: Final and Extras

1.Put your keyboard in pairing mode and attach your bluetooth dongle to usb hub.

2.Start your OS.

3.Now you are ready to use your dongle with a bluetooth keyboard.

Also you can use hcitool con command for testing your connection. It must show you your keyboard in output.

Good luck!


1.I am working on a script for periodic connection control. Because connection is wireless and can be lost easily