Skip navigation
This discussion is archived

Caps Lock

2279 Views 3 Replies Latest reply: May 9, 2010 11:12 PM by Hiroto RSS
Cande Calculating status...
Currently Being Moderated
May 7, 2010 1:04 AM
My script needs to see if caps lock is on or off

Solution can be plain AppleScript thing or unix thing.

MacBook Pro, Mac OS X (10.6.1)
  • Budgie Level 4 Level 4 (1,120 points)
    Currently Being Moderated
    May 9, 2010 7:00 PM (in response to Cande)
    Hi Cande

    this could help


    Message was edited by: Budgie
    10.4.11 G5 PPC10.4.11 G5 PPC 1.8Ghz 2.GB Ram - 2Ghz 2.5GB Ram - 10.5.6 (Alumi
  • red_menace Level 6 Level 6 (14,275 points)
    Currently Being Moderated
    May 9, 2010 7:09 PM (in response to Cande)
    For a command line tool, there is also this one:
    MacBook Pro, Mac OS X (10.6.3), (and various older stuff keeping dust off the shelves)
  • Hiroto Level 5 Level 5 (4,810 points)
    Currently Being Moderated
    May 9, 2010 11:12 PM (in response to Cande)

    You can build a simple command line programme to get current key modifiers' hardware state.

    1) Save C source below as plain text file named, .e.g, GetCurrentKeyModifiers.c, on desktop.

    #include <Carbon/Carbon.h>

    int main (int argc, const char * argv[]) {
    unsigned int m = GetCurrentKeyModifiers();
    printf("%u ", m);
    return 0;

    2) In, change current directory to desktop and use gcc to compile it as follows.
    (You need Developer Tools installed to use gcc.).

    cd ~/Desktop
    gcc -framework Carbon -o GetCurrentKeyModifiers GetCurrentKeyModifiers.c

    3) Test the yielded command in


    If it prints 1024 (or any number N where N & 0x0400 = 1) when CAPS LOCK is on, you're done.

    Now in AppleScript you'd write as follows to detect caps lock.

    do shell script ("~/Desktop/GetCurrentKeyModifiers")
    set n to result as number
    set _capslocked to n div 1024 mod 2 = 1


    Event Modifier Constants
    enum {
    activeFlagBit =0,
    btnStateBit =7,
    cmdKeyBit =8,
    shiftKeyBit =9,
    alphaLockBit =10,
    optionKeyBit =11,
    controlKeyBit =12,
    rightShiftKeyBit =13,
    rightOptionKeyBit =14,
    rightControlKeyBit =15
    typedef UInt16 EventModifiers;

    Good luck,
    Mac OS 9.1.x


More Like This

  • Retrieving data ...

Bookmarked By (0)


  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.