import { Injectable } from '@angular/core' ; import { ReplaySubject } from 'rxjs/internal/ReplaySubject' ; @ Injectable ( ) export class VirtualKeyboardService { public shift$ : ReplaySubject < boolean > = new ReplaySubject ( 1 ) ; public capsLock$ : ReplaySubject < boolean > = new ReplaySubject ( 1 ) ; public caretPosition$ : ReplaySubject < number > = new ReplaySubject ( 1 ) ; private capsLock = false ; private shift = false ; param { boolean } value public setShift ( value ) { this . shift = value ; this . shift$ . next ( this . shift ) ; this . setCapsLock ( this . shift ) ; } param { boolean } value public setCapsLock ( value ) { this . capsLock = value ; this . capsLock$ . next ( value ) ; } /**
     * Toggle for Shift, note that this also toggles CapsLock
     */ public toggleShift ( ) { this . shift = ! this . shift ; this . shift$ . next ( this . shift ) ; this . setCapsLock ( this . shift ) ; } /**
     * Toggle for CapsLock
     */ public toggleCapsLock ( ) { this . capsLock = ! this . capsLock ; this . capsLock$ . next ( this . capsLock ) ; } param { number } position public setCaretPosition ( position ) { this . caretPosition$ . next ( position ) ; } /**
     * Method to reset Shift and CapsLock values to default ones.
     */ public reset ( ) { this . setShift ( false ) ; } }