Make sure that the game window has input focus by clicking into it.
If that doesn’t help and you happen to use some extra invasive third party antivirus (i.e. anything other than Windows Defender), get rid of it. Imaginable that one or the other super annoying AV program may prevent keyboard hooks.
Also make sure that you don’t have any background apps running that also hook into games, typical candidates would be any kind of CPU/GPU utilities, gaming overlays, PC vendor bloatware, messengers, recording software and similar things.