Checking CAPS LOCK state at startup

arborist 2015-09-20

Checking the CAPS LOCK state at start-up of an application (e.g. an password-entry) can be done with a little help from a small wonderful command-line tool: xdotool .

In the example below I let xdotool fire a minor 'x' to see what character will be received by the previous focused label-widget. In case of a major 'X' the CAPS LOCK key had been pressed obviously and a corresponding message will be displayed.

label .message -text {CAPS LOCK disabled} -textvariable MESSAGE -width 20
bind .message <KeyPress> {if {%N eq 88} {set ::MESSAGE {CAPS LOCK enabled}}}
pack .message
focus .message
catch {exec xdotool key x}

RLE (2015-09-20): Note, xdotool is an X11 tool, so this solution will work on Linux and (likely) MacOSX, but not windows.