function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Amit Singh 2236Amit Singh 2236 

Lightning code to track caps lock on and off Functionality in login form page

Lightning code to track caps lock on and off Functionality in login form page
Ajay K DubediAjay K Dubedi
Hi Amit,

I have gone through your issue and found a solution. Please check the link below - 

https://salesforce.stackexchange.com/questions/264943/detecting-caps-lock-not-working/264951#264951

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
 
Deepali KulshresthaDeepali Kulshrestha
Hi Amit,

I've gone through your requirement and you can use the below javascript code:

It should not be onkeypress, but should be onkeyup.

In theory, the keydown and keyup events represent keys being pressed or released, while the keypress event represents a character being typed.
The implementation of the theory is not same in all browser

<span onkeyup="{!c.keyCheck}">
    <lightning:input aura:id="capsLock" label="test" />
</span>
Js:

({
    keyCheck : function(component, event, helper) {
    // Caps Lock numeric value: 20
    console.log(event.which);
    if (event.which == 20) {
        var capsLockMessage = component.find("capsLockMessage");
        $A.util.toggleClass(capsLockMessage, "slds-hide");
        alert("Caps Lock was pressed");
    }
}
})



I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
 
Amit Singh 2236Amit Singh 2236
Thanks Ajay and Deepali