Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

CapsLock confirmation dialog


  • Please log in to reply
No replies to this topic
cranky
  • Members
  • 3 posts
  • Last active: Sep 21 2011 12:44 PM
  • Joined: 20 Mar 2010
I keep hitting CapsLock accidentally, and using
ToggleKeys doesn't work if your sound
is muted for any reason. So I needed a popup
confirmation dialog whenever I hit CapsLock.
Here it is. Paste it in your AutoHotkey.ini

#SingleInstance force

;**********************************************
;** CapslockConfirm macro
;   get user confirmation before changing Capslock state
;
; @version 1.0 cranky 07-Oct-2009
; @version 1.1 cranky 17-Mar-2010; test for VMware
;
;   NOTE macro gets confused when ALSO being run in a VM,
;   so we disable this macro if VMware is running.
;   (confirmation will occur in Guest but not in Host)
;   * if you run VirtualPC etc this will have to be tweaked *
;
;   NOTE "#SingleInstance force|ignore" is required
;
Capslock::
{
    GetConfirm = 1
    TestClass = VMUIFrame ; tweak as required

    IfWinExist, ahk_class %TestClass% 
    {
        GetConfirm = 0 ;
    }

    KeyIsDown := GetKeyState("Capslock" , "T") ;
    KeyWait, Capslock  ; Wait for user to physically release it.

    If GetConfirm
    {
        ; Question=32; Yes/No=4; (==36) 
        If KeyIsDown
        {
            MsgBox, 36, CapslockConfirm, Are you sure you want to turn Caps Lock OFF?
        }
        Else
        {
            MsgBox, 36, CapslockConfirm, Are you sure you want to turn Caps Lock ON?
        }
        IfMsgBox, No
        {
            If KeyIsDown
            {
                SetCapsLockState , On ;
            }
            Else
            {
                SetCapsLockState , Off ;
            }
        }
        Else
        {
            If KeyIsDown
            {
                SetCapsLockState , Off ;
            }
            Else
            {
                SetCapsLockState , On ;
            }
        }
    }
    Else
    {
        ; pass on the original key event:
        If KeyIsDown
        {
            SetCapsLockState , Off ;
        }
        Else
        {
            SetCapsLockState , On ;
        }
    }
    ; required to prevent reentry "sometimes" (why?):
    Sleep, 110
    Exit ;
}