You are on page 1of 13

5/5/2015

Virtual Keyboard for the Raspberry P

ozzmaker.com

Virtual Keyboard for the Raspberry Pi


June 30, 2014 | Mark Williams | 40 Comments

Matchbox-keyboard is an on screen virtual or software keyboard which works well for small touchscreen TFTs
connected to a Raspberry Pi.

http://ozzmaker.com/2014/06/30/virtual-keyboard-for-the-raspberry-pi/?utm_source=feedly

1/13

5/5/2015

Virtual Keyboard for the Raspberry P

Matchbox-keyboard also uses XML files to specify the layout of the keys, which makes it highly customizable.
The touchscreen used in the above video is a PiScreen.
1. Install prerequisite development files
pi@raspberrypi~$sudoaptgetinstalllibfakekeydevlibpngdevlibxftdevautoconflibtooly

2. Install and compile matchbox-keyboard


pi@raspberrypi~$gitclonehttps://github.com/mwilliams03/matchboxkeyboard.git
pi@raspberrypi~$cdmatchboxkeyboard
pi@raspberrypi~$./autogen.sh
pi@raspberrypi~$make
pi@raspberrypi~$sudomakeinstall

Installation of the shared matchbox libraries needs to be done after the installation of matchbox-keyboard.
pi@raspberrypi~$sudoaptgetinstalllibmatchbox1y

3. Create toggle script to start or stop matchbox-keyboard


We will now create a script to toggle the keyboard on and off. And then add a menu item to access the script as
well as add an icon to the task bar for easy access.

Create a new file;


pi@raspberrypi~$sudonano/usr/bin/togglematchboxkeyboard.sh

And copy in the text below;


#!/bin/bash
#This script toggle the virtual keyboard
PID=`pidof matchbox-keyboard`
if [ ! -e $PID ]; then
http://ozzmaker.com/2014/06/30/virtual-keyboard-for-the-raspberry-pi/?utm_source=feedly

2/13

5/5/2015

Virtual Keyboard for the Raspberry P

killall matchbox-keyboard
else
matchbox-keyboard&
fi

Now make it executable;


pi@raspberrypi~$sudochmod+x/usr/bin/togglematchboxkeyboard.sh

We will now add an item to the start menu.


pi@raspberrypi~$sudonano/usr/local/share/applications/togglematchboxkeyboard.desktop

Copy in this text;


[Desktop Entry]
Name=Toggle Matchbox Keyboard
Comment=Toggle Matchbox Keyboard
Exec=toggle-matchbox-keyboard.sh
Type=Application
Icon=matchbox-keyboard.png
Categories=Panel;Utility;MB
X-MB-INPUT-MECHANSIM=True

To create an icon on the task bar, open up the LXDE panel config;
pi@raspberrypi~$nano~/.config/lxpanel/LXDE/panels/panel

If the above file is empty, then it is most likely that you have a newer version of Raspbian, especially if you are
using a Pi 2. You then would need to edit the panel config at this location;
pi@raspberrypi~$nano~/.config/lxpanelpi/LXDE/panels/panel

Find this section of config (it is near the bottom);


Plugin {
type = launchbar
http://ozzmaker.com/2014/06/30/virtual-keyboard-for-the-raspberry-pi/?utm_source=feedly

3/13

5/5/2015

Virtual Keyboard for the Raspberry P

Config {
Button {
id=lxde-screenlock.desktop
}
Button {
id=lxde-logout.desktop
}
}

and change it to;


Plugin {
type = launchbar
Config {
Button {
id=toggle-matchbox-keyboard.desktop
}
Button {
id=lxde-screenlock.desktop
}
Button {
id=lxde-logout.desktop
}
}

More Information
Matchbox-keyboard can be started from the command line with the below statement. This needs to be run from a
command prompt within X which is running on the touch screen;
pi@raspberrypi~$matchboxkeyboard

Alternately, if you have SSHd in from another PC, use;


pi@raspberrypi~$DISPLAY=:0.0matchboxkeyboard

This will load the default keyboard layout, seen here;

http://ozzmaker.com/2014/06/30/virtual-keyboard-for-the-raspberry-pi/?utm_source=feedly

4/13

5/5/2015

Virtual Keyboard for the Raspberry P

Matchbox-keyboard can also resize the window with the -s integerargument. Integer is a value between
30%-100% of the screen width.
Here is the defualt keyboard layout loaded at 50% of screen width;
pi@raspberrypi~$matchboxkeyboards50

Matchbox-keyboard also supports custom keyboards, and there are a few loaded with the install into
/usr/local/share/matchbox-keyboard/. It is very easy to build your own.
pi@raspberrypi~$matchboxkeyboards50extended

http://ozzmaker.com/2014/06/30/virtual-keyboard-for-the-raspberry-pi/?utm_source=feedly

5/13

5/5/2015

Virtual Keyboard for the Raspberry P

Raspberry Pi Dashboard
Connect, control and monitor your
Raspberry Pi. Free account sign up

SHARE THIS:

Twitter

KEYBOARD

Facebook

PISCREEN

PITFT

RASPBERRY PI

TFT

TOUCHSCREEN

40 THOUGHTS ON VIRTUAL KEYBOARD FOR THE RASPBERRY PI


Pingback: Virtual keyboard for the #RaspberryPi | Raspberry Pi Pod

Pingback: PiScreen

TFT 3.5


| Unof cial of Raspberry Pi Fan in Thailand

Pingback: codescaling | Maker Catchup: BeagleBone GSM Basestation, Pi ScreenKeyboards, Tiny Clocks

Pingback: Add a Virtual Keyboard to a Raspberry Pi | Binary Reveux

Pingback: Add a Virtual Keyboard to a Raspberry Pi|The Cannabis Strain Directory Blog

http://ozzmaker.com/2014/06/30/virtual-keyboard-for-the-raspberry-pi/?utm_source=feedly

6/13

5/5/2015

Virtual Keyboard for the Raspberry P

Pingback: <CONTENT /> v.6

Pingback: Add a Virtual Keyboard to a Raspberry Pi | Hihid News

dreamshader
AUGUST 27, 2014 AT 5:53 AM

Remember to install libxft-dev if not done befor (sudo apt-get -y install libxft-dev).
Otherwise the error:
configure: error: *** Required Xft Library not found ***
will occur.
rgds,
-ds-

mwilliams03
AUGUST 27, 2014 AT 10:03 AM

Thanks I have added libxft-dev to the instructions.

frans
AUGUST 28, 2014 AT 6:59 AM

./autogen.sh this doesnt work


./autogen.sh: 2: ./autogen.sh: autoreconf: not found

mwilliams03
AUGUST 28, 2014 AT 2:20 PM

you need to install autoconf and libtool


sudo apt-get install autoconf libtool

frans
AUGUST 29, 2014 AT 1:20 AM

DISPLAY=:0.0 matchbox-keyboard
matchbox-keyboard: error while loading shared libraries: libmatchbox-keyboard.so.0: cannot open
shared object file: No such file or directory
i see nothing

mwilliams03
http://ozzmaker.com/2014/06/30/virtual-keyboard-for-the-raspberry-pi/?utm_source=feedly

7/13

5/5/2015

Virtual Keyboard for the Raspberry P

AUGUST 29, 2014 AT 11:59 AM

Did you install the Matchbox libraries?


sudo apt-get install libmatchbox1 -y

frans
AUGUST 29, 2014 AT 6:15 PM

libmatchbox1 is already the newest version.

Blaubart
SEPTEMBER 4, 2014 AT 7:18 PM

Im using Rasbian Jessie with Kernel 3.12.26 and I cant install matchbox-keyboard. I used the following
commands:
git clone https://github.com/mwilliams03/matchbox-keyboard.git
cd matchbox-keyboard
./autogen.sh
make
the results:
base-fragment-et_EE.xml.in > base-fragment-et_EE.xml.tmp
cp base-fragment-et_EE.xml.tmp base-fragment-et_EE.xml
make[2]: *** No rule to make target keyboard-extended.xml.in, needed by keyboard-extended.xml.tmp.
Schluss.
rm base-fragment-da_DK.xml.tmp base-fragment-et_EE.xml.tmp
make[2]: Leaving directory /home/pi/matchbox-keyboard/layouts
Makefile:486: recipe for target all-recursive failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory /home/pi/matchbox-keyboard
Makefile:375: recipe for target all failed
make: *** [all] Error 2

Arc
SEPTEMBER 13, 2014 AT 11:45 PM

in ~/matchbox-keyboard/layouts/, keyboard-extended.xml.in file is missing.


cd ~/matchbox-keyboard/layouts/
cp keyboard-extended.xml keyboard-extended.xml.in
then retry.

Sancho
http://ozzmaker.com/2014/06/30/virtual-keyboard-for-the-raspberry-pi/?utm_source=feedly

8/13

5/5/2015

Virtual Keyboard for the Raspberry P

SEPTEMBER 21, 2014 AT 9:53 PM

Thank you for your tip!

Saad
SEPTEMBER 12, 2014 AT 11:49 PM

First of all thanks for the awesome PiScreen. I am a beginner with Raspberry Pi. I was wondering if it is
possible to support multiple PiScreens simultaneously with a single Raspberry Pi or Banana Pi or any of its
high-end variants? Can I connect PiScreen using USB port and what can I do to achieve this?
I shall be grateful for the response and any helpful details/insights into this.
Thanks
S

Juan Fernando
SEPTEMBER 14, 2014 AT 6:35 AM

hello it is a good post, but now i need install extended, can you tell made a tutorial how to make it??

chris
OCTOBER 28, 2014 AT 7:23 AM

sudo nano /usr/bin/toggle-matchbox-keyboard.sh


change
matchbox-keyboard&
to
matchbox-keyboard -s 75 extended&

WIlliam
OCTOBER 31, 2014 AT 3:39 PM

Is it possible to add the following characters on the keyboard {, }, &, and | and numbers? If so, how?

Mark Williams
OCTOBER 31, 2014 AT 3:50 PM

first try loading the extended keyboard and see if that gives you what you want
matchbox-keyboard extended
http://ozzmaker.com/2014/06/30/virtual-keyboard-for-the-raspberry-pi/?utm_source=feedly

9/13

5/5/2015

Virtual Keyboard for the Raspberry P

Otherwise, read the README in the source directory. It has a section titled Making your own keyboard
layouts

JanKinander
DECEMBER 3, 2014 AT 6:18 PM

How do you set the language xml file you wish to use? And how can languages be switched during use?

Joe
JANUARY 26, 2015 AT 5:26 AM

I could not get the toggle script to work properly until I changed the line:
PID=pidof matchbox-keyboard
To this:
PID=$(pidof matchbox-keyboard)
It would only keep launching additional keyboards before making this change.
I cant tell you exactly why I just kept looking at examples of scripts and looking for other ways to write it
until I got it to work.

Etienne
FEBRUARY 6, 2015 AT 1:38 AM

Hello,
I have change
matchbox-keyboard -s 75 extended&
In:
sudo nano /usr/bin/toggle-matchbox-keyboard.sh
But, when i launch the matchbox on the menu, it alway launch the Standart non extended keyboard. whats
wrong?
Alors after changer text in ~/.config/lxpanel/LXDE/panels/panel and rebboted the device, the line i have
editer have diseapear, now , POWER and LOCK icon has diseaper from the taskbar, i dont know why

Etienne
FEBRUARY 6, 2015 AT 2:46 AM

Hello,
Its now working, i have erase all space or tab space and now its working (on your example, have space
http://ozzmaker.com/2014/06/30/virtual-keyboard-for-the-raspberry-pi/?utm_source=feedly

10/13

5/5/2015

Virtual Keyboard for the Raspberry P

and Tab and i have delete it and woking great now)


I have just a question, it is possible to have a more extended keyboard (like with Up,Down,Right,Left,
inser, home, delete, etc Key)?
Best regards.
Etienne

Mark Williams
FEBRUARY 6, 2015 AT 5:00 PM

Some instructions to create your own layouts here;


https://github.com/xlab/matchbox-keyboard
http://wiki.openmoko.org/wiki/Change_matchbox_keyboard_layout
You can also find some examples here;
/usr/local/share/matchbox-keyboard/

Richard
FEBRUARY 26, 2015 AT 4:48 PM

I have followed the installation instructions and the standard matchbox keyboard works fine. When I try to
get the extended version to work:
matchbox-keyboard extended
I get Segmentation fault. Can you help me troubleshoot this?

Fernando Cornejo
MARCH 9, 2015 AT 3:37 AM

got the same. did you solve it?

Lester
MARCH 6, 2015 AT 7:52 AM

This edit location has changed for the Pi2


pi@raspberrypi ~ $ nano ~/.config/lxpanel/LXDE/panels/panel
it is now
pi@raspberrypi ~ $ nano ~/.config/lxpanel/LXDE-pi/panels/panel
Will this affect any of the coding?
It seems to work.

Fernando Cornejo
http://ozzmaker.com/2014/06/30/virtual-keyboard-for-the-raspberry-pi/?utm_source=feedly

11/13

5/5/2015

Virtual Keyboard for the Raspberry P

MARCH 8, 2015 AT 5:49 PM

I cant make the toggle work, could you help me to install the last version (https://github.com/xlab/matchboxkeyboard). What i really want is to make the virtual keyboard runs on startup. Please some help, Im newbie

Fernando Cornejo
MARCH 12, 2015 AT 10:53 AM

how can I put it always on top?

Guus
MARCH 17, 2015 AT 10:12 PM

I executed all steps in the tuturial, but same as frans (AUGUST 29, 2014 AT 1:20 AM) I get the following error
message:
matchbox-keyboard: error while loading shared libraries: libmatchbox-keyboard.so.0: cannot open shared
object file: No such file or directory
uname -a
Linux raspberrypi 3.18.9-v7+ #767 SMP PREEMPT Sat Mar 7 21:52:35 GMT 2015 armv7l GNU/Linux
Can you please advise? Thanks

Fernando Cornejo
MARCH 18, 2015 AT 11:51 PM

Do you install libmatchbox libraries? (sudo apt-get install libmatchbox1 -y )

Guus
MARCH 19, 2015 AT 12:26 AM

Hi Fernando, I appreciate your reply. However:


libmatchbox1 is already the newest version.
Any other advise?
Thanks,
Guus

jim belmore
MARCH 19, 2015 AT 3:26 AM

Hi all, first of all Mark I appreciate all the work that has gone in to this. Very useful tool for the pi with the
http://ozzmaker.com/2014/06/30/virtual-keyboard-for-the-raspberry-pi/?utm_source=feedly

12/13

5/5/2015

Virtual Keyboard for the Raspberry P

small touchscreen. First of all the tutorial is well written and concise which I appreciate. In the line X-MBINPUT-MECHANSIM=True is it supposed to be MECHANISM or how its typed? I also have run through this
two times. The first time I felt that I had missed installing libmatchbox1 in the appropriate sequence so I
reimaged and tried the script again installing libmatchbox at an earlier time. I still receive the
matchbox-keyboard: error while loading shared libraries: libmatchbox-keyboard.so.0: cannot open shared
object file: No such file or directory
I am using the raspian pitft image PiTFT28R_raspbian140620_2014_08_25. Ive checked the error logs and
no error seems to be logged.
Any and all advice is appreciated this tool would cure a number of remote uses I have in mind for this unit.
thanks Jim

Amit Kushwaha
APRIL 4, 2015 AT 11:08 PM

I am getting this error


configure: error: *** You need to install libfakekey from MB SVN ***

Jim
APRIL 19, 2015 AT 12:08 AM

Getting Directory ( ~/.config/lxpanel-pi/LXDE/panels/panel) not found when trying to write the code to the
file.

khusro kkan
MAY 3, 2015 AT 1:09 AM

hi Jim
i also got this error.
did u solve it

Matthew Grant
MAY 5, 2015 AT 10:53 AM

Hi.
Ive installed the keyboard as per instructions but after running it I cant open File Manager without a reboot
and then if I run matchbox-keyboard File Manager will not open.
Anyone else having this problem? How can I fix it?
Thanks

http://ozzmaker.com/2014/06/30/virtual-keyboard-for-the-raspberry-pi/?utm_source=feedly

13/13

You might also like