Version 1 of Checking CAPS LOCK state at startup

Updated 2015-09-20 18:02:46 by arborist

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

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

proc main {} {

        wm resizable . 0 0
        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
        update
        catch {exec xdotool key x}
        after 3000 exit
        }

main