I have found a Solution don't restart X if the real keyboard don't work any more.
There are many Programs for Linux, which emulate by Mouse a virtual keyboard and are used on normal PC and some on Nokia and other Devices.
For GNOME, hardly for KDE
For some Devices and PC
A Debate about virtual Keyboard
But I think xvkbd is the best for this. This is Gnome Program (GTK) but works good with KDE. It is very fast and don't need much Resource.
emerge -a xvkbd xbindkeys
Make with KMenu Edit a Submenu and a Item for xvkbd
in K menu / System / Virtuel keyboard / Xvkbd
Download from this Site to Yours PC xvkbd.gif in
Start KIconEdit and open xvkbd.gif, change Image dimension from 200x147 to 45x35 and write as xvkbd.png
Select this Icon in KMenu Edit for xvkbd
Write in the Command Line for xvkbd. Security is allways needed.
xvkbd -secure -geometry 750x350+262+84 -always-on-top &
If You disturb do write without pressing to left Mouse Button, You can this could exclude in xvkbd Menu.
You could see the Site from xvkbd for more Examples and