CAPSLOCK only sometimes equals ShiftLock

by Michael S. Kaplan, published on 2005/01/25 08:34 -08:00, original URI:

Tor Lillqvist suggested I talk a little about the difference between CAPSLOCK and ShiftLock --

Something you might want to blog about some day: the difference between "CapsLock" and "ShiftLock". Especially determining programmatically whether the "VK_CAPITAL" key acts as CapsLock or ShiftLock for a certain keyboard layout (input locale identifier). (Something I needed to do recently, for somewhat complex reasons)

Currently I do it by checking with ToAsciiEx(). I select a key that generates different characters with and without VK_SHIFT, and where the result from the shifted key isn't simply the uppercase equivalent of the unshifted one. I.e. typically my code would select a key from the "digit" row.

I then check again with VK_CAPITAL toggled (and VK_SHIFT off), and if the resulting char is the same that just VK_SHIFT produced, I know that VK_CAPITAL should act as ShiftLock.

Well, of course I would always suggest using ToUnicodeEx instead of ToAsciiEx.... :-)

Of course its not that simple since it is a per-key setting (as you point out, usually the CAPSLOCK key does not cause the number keys to display their shift states). And then comes features like SGCAPS that take over the CAPSLOCK key in a big way. Check out the Hebrew keyboard some time in MSKLC and you'll see what I mean -- it just wreaks havoc with the notion of the key labelled CAPSLOCK locking the 'CAPS' state. The price of adding two new shift states.

The setting also gets weird when you add dead keys to the mix -- anytime you call ToUnicode or ToUnicodeEx and the key is a dead key you will have that weird stateful situation which will affect the next call in the same thread. Though of course people who author keyboard layouts with dead keys that span multiple shift states probably do not like their users too much -- thats a hard typing task!

The setting in question here is actually available in MSKLC. We argued about the name of the setting for some time before finally settling on the "caps = shift" option. I had voted for "caps == shift" but was outvoted by the program managers to 2 to 1 -- maybe I should have invited some other developers?

Anyway, the MSKLC setting is actually automatically applied when the characters are cased variants of each other, and it is used in validation -- if the two characters are case pairs yet this option is not enabled (or if they are not case pairs yet the option IS enabled), you get a warning. But this is okay if it is intentional -- usually, it's not, though. After MSKLC was available we found out how often Microsoft had done this setting improperly in the build-in keyboards in Windows!

So, the summary -- for the CAPSLOCK to act as a ShiftLock, one must explicitly ask it to be so in the keyboard layout -- and often the layout author does not do this (even if that was probably the intention).

This post brought to you by "±" (U+00b1, a.k.a. PLUS-MINUS SIGN)

# Philip Newton on Tuesday, January 25, 2005 10:18 PM:

"We argued about the name of the setting for some time before finally settling on the "caps = shift" option. I had voted for "caps == shift) but was outvoted"

I'm not sure what the two different options mean, or how they are different.

Is the number of equals signs significant? Is the closing parenthesis on your chosen option significant, or is it a typo?

# Michael Kaplan on Tuesday, January 25, 2005 10:54 PM:

The closing parenthesis was a typo -- fixed now.

The meaning is that the CapsLock key has the same functionality as the Shift key (which it often does for letters of languages which have case)....

On the other hand, they would not do the same thing on the number keys.

The two equals signs matches the C/C++/C# convention of equality. :-)

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

referenced by

2006/10/06 If you hate the CAPS LOCK key, please read this!

2006/04/10 Getting all you can out of a keyboard layout, Part #8

go to newer or older post, or back to index or month or day