Hacker News new | ask | show | jobs
by smodo 1050 days ago
If you need capslock that’s easy to emulate in software nowadays. For instance KDE has a default option to toggle capslock by pressing both shift keys.
1 comments

I use that, but unfortunately it's not that easy (also I'm pretty sure it's not KDE-specific - most keyboard stuff even works in the console!).

Let's use `xev`'s `state` field for reference:

First, `state & 0x10` is NumLock which is the only modifier that's often set. Software knows to mask out this and a couple other modifiers when dispatching keyboard shortcuts.

Second, `state & 0x02` is CapsLock. Software that detects CapsLock as a modifier will work correctly with double-shift-as-capslock.

Unfortunately, `state & 0x01` is Shift. Software that reads CapsLock as a keysym (often e.g. games that use it as a "turbo" toggle) will often fail, because when double-shift is pressed, the shift modifier has been set. And it's generally considered a bug to ignore modifiers when dispatching keyboard events.

Unfortunately, there is no event for just "`state` changed", it is only dispatched alongside some other mouse/keyboard event. If you press just `shift` you'll see that it doesn't update yet for the just-pressed key (and fundamentally cannot due to how it has to work to switch between keycode->keysym mappings).