You could use the
xinput --test-xi2 --root command (man xinput), where
test-xi2 means logging input devices, and
--root is to log from so called root window (a x11 specific concept). It would show you when and which key pressed in the system, mouse clicks, and even mouse motion coordinates. It solves your
3 points, you just need to parse these events.
2 point is trickier. You can use
xev -root command which would monitor all X events in the system, including things like (dis) appearing windows, entering/exiting focus of a particular window, etc. You have to parse its output, and show a human-readable description of what is happening. Btw, the command logs pressed keys also.
A caveat: it is, obviously, a great security hole, which dates back to times when Xorg was created, and nobody needed to care. For this reason nowadays X11 is being replaced with the Wayland protocol (it is in the essence a X12, but as not backward compatible, the protocol land called another way), which WMs are implementing ATM. It isn't quick process as the protocol demands much more from WM, but Fedora 25 seem to finally have Wayland session enabled by default. KWin is also catching up. And your script not going to work on Wayland. This doesn't mean you can't do it — I think, you can. But you'd need to work closely with a particular WM of a particular DE, and the script would be not a stand alone bash script, but rather an addon to a WM.