So let me get this clear: You boot up, log in, and initially your mouse and keyboard work fine at the desktop; everything is copacetic. Then at some point in your session, all of a sudden and out of the blue, your keyboard doesn't work and your mouse clicks stop having any effect, though you can still move your mouse. Ctrl-Alt-F1 (and presumably the other "F" keys) still work though, and you can even switch back to X11 with Ctrl-Alt-F7.
Now, you said above that if you hover over something that is activatable just by hovering over it, that the object will activate -- e.g. a popup will appear. Can you tell us just what kind of popup this is, such as what application it's in? Is it on a Web page or is it in a desktop application, for example? I've seen that Web browsers can sometimes display popups even when some other application is grabbing the keyboard and mouse. It's weird how they do that.
Also, which applications do you have open when this strange behavior occurs, if I may ask? This is an important question to answer. Clearly, this behavior is caused by some application grabbing input focus; it could be the MATE Screensaver, it could be Firefox (the annoying "Update Available" popups have a strong tendency to do this -- believe me, I have experience with this), it could be something you didn't even know you were running. But if maybe the next time you encounter this problem, you can at least look down at the Window List on the panel and make a note of what you have open, and also note down what window was actively on top on the screen at the time of the unresponsiveness, that would be very useful.
Finally, while @tkn's advice about Alt-SysRq-R was well-intentioned and generally good advice, I find it very unlikely to actually work for you. If the system responds to Ctrl-Alt-F1 when this grabbing stuff happens, then clearly the kernel (and even X) is still receiving input from the keyboard and responding to it. Similarly, if moving the mouse works, the mouse driver still works too. So "restoring" the keyboard to a "normal" state is probably not going to work, since the keyboard itself is already in a normal state.
However, if you could, there is one other thing I'd like you to try when this next happens. When the weird grabbing behavior occurs, switch to the console (Ctrl-Alt-F1), and log in there as the same user account as which you're logged in on X. Then, still at the console, run the following commands:
sudo apt install xdotool
DISPLAY=":0" xdotool key "XF86LogGrabInfo"
Then, still at the console, look in the logfile for the X server, at the bottom or near-bottom of the file:
less /var/log/Xorg.0.log
...or, if you've already pkill
'ed the X server at least once, possibly:
less /var/log/Xorg.1.log
(you might need to run these as sudo
).
According to this Unix & Linux Stack Exchange post, you should see an entry in the logfile that looks something like this:
[1199428.782] (II) Printing all currently active device grabs:
[1199428.782] Active grab 0x4c00000 (core) on device 'Virtual core pointer' (2):
[1199428.782] client pid 15620 /usr/lib/firefox/firefox
[1199428.782] at 1199423728 (from active grab) (device thawed, state 1)
[1199428.782] core event mask 0x7c
[1199428.782] owner-events true, kb 1 ptr 1, confine 0, cursor 0x0
[1199428.782] (II) End list of active device grabs
At the very least, it should tell you the process ID and name of the offending grabber. In this example, Firefox can't seem to keep its hands to itself.
I excittedly await your reply and new information regarding this issue -- assuming it didn't spontaneously go away. Always a possibility; maybe an upgrade fixed it.
Thanks in advance.