mirror of https://github.com/abpframework/abp.git
2 changed files with 31 additions and 0 deletions
@ -0,0 +1,30 @@ |
|||
import { Directive, EventEmitter, HostListener, Output } from '@angular/core'; |
|||
|
|||
@Directive({ |
|||
standalone: true, |
|||
selector: '[abpCapsLock]', |
|||
}) |
|||
export class TrackCapsLockDirective { |
|||
@Output('abpCapsLock') capsLock = new EventEmitter<Boolean>(); |
|||
|
|||
@HostListener('window:keydown', ['$event']) |
|||
onKeyDown(event: KeyboardEvent): void { |
|||
this.capsLock.emit(this.capS(event)); |
|||
} |
|||
@HostListener('window:keyup', ['$event']) |
|||
onKeyUp(event: KeyboardEvent): void { |
|||
this.capsLock.emit(this.capS(event)); |
|||
} |
|||
|
|||
capS(e) { |
|||
var s = String.fromCharCode(e.which); |
|||
if ( |
|||
(s.toUpperCase() === s && s.toLowerCase() !== s && e.shiftKey) || |
|||
(s.toUpperCase() !== s && s.toLowerCase() === s && e.shiftKey) || |
|||
e.getModifierState('CapsLock') |
|||
) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue