Please try this:
Reboot, but do not log in on the GUI.
Try to open a text terminal somehow (virtual termina, or by ssh) and see whether that's stable.
(I asked this as comment originally. It did work to get a stable text terminal as hoped.)
Now, assuming that works - great!
Now, you have a broken system, and an old version "12.04 LTS".
Fixing is easier in a new version, and I see not much reason why the problem should still exist after changing out all the software on the machine.
So, let's just do that, update to Ubuntu 14.4 and see how it works out - any objections?
If that's not possible, you can start with a normal package update anyway... let's see...
Did not help? Hmmm...
One more shot into the blue: We uninstall, and reinstall all the input related parts of X:
sudo apt-get --purge autoremove xserver-xorg-input-all
sudo apt-get install xserver-xorg-input-all
Hope that helps- otherwise, we'll need to actually search the problem, I think...
Like... What kind of graphics, which driver do you use?
For directions to upgrade to the current Ubuntu version, see
How to install software or upgrade from an old unsupported release?