Problem
I can’t determine whether this happens randomly or under specific circumstances, but when I switch windows (e.g., by clicking or using Alt + Tab), the keyboard occasionally stays connected to the previous window. This is quite frustrating because it seems like nothing is happening as I type, while the text is actually being entered in the previous window.
Here are my Window Focus Tweaks:

Related topics
I've found these two really old posts on this topic:
My system
- Ubuntu version: 24.04.1 LTS
- Windowing system: X11
- GNOME: GNOME Shell 46.0
Notes
Note 1: When I was using Ubuntu 22.04, I experienced an issue with the application switching shortcut. I’m not sure if it’s related to my current problem or not.
Note 2: On Ubuntu 20.04, I had to switch from Wayland to X11 to make Color picker working.
Potential solution
Using Wayland solve the issue (if you can do without X11).