11var GetObjectValue = require ( '../../../utils/object/GetObjectValue' ) ;
2+ var ResetKeyCombo = require ( './ResetKeyCombo' ) ;
3+ var ProcessKeyCombo = require ( './ProcessKeyCombo' ) ;
4+ var KeyComboMatchEvent = require ( './KeyComboMatchEvent' ) ;
25
36// Keys can be either:
47//
@@ -8,6 +11,8 @@ var GetObjectValue = require('../../../utils/object/GetObjectValue');
811
912var KeyCombo = function ( keyboardManager , keys , config )
1013{
14+ if ( config === undefined ) { config = { } ; }
15+
1116 // Can't have a zero or single length combo (string or array based)
1217 if ( keys . length < 2 )
1318 {
@@ -68,13 +73,53 @@ var KeyCombo = function (keyboardManager, keys, config)
6873
6974 // If previously matched and they press Key 1 again, will it reset?
7075 this . resetOnMatch = GetObjectValue ( config , 'resetOnMatch' , false ) ;
76+
77+ // If the combo matches, will it delete itself?
78+ this . deleteOnMatch = GetObjectValue ( config , 'deleteOnMatch' , false ) ;
79+
80+ var _this = this ;
81+
82+ var onKeyDownHandler = function ( event )
83+ {
84+ if ( _this . matched || ! _this . enabled )
85+ {
86+ return ;
87+ }
88+
89+ var matched = ProcessKeyCombo ( event . data , _this ) ;
90+
91+ if ( matched )
92+ {
93+ _this . manager . events . dispatch ( new KeyComboMatchEvent ( _this , event ) ) ;
94+
95+ if ( _this . resetOnMatch )
96+ {
97+ ResetKeyCombo ( _this ) ;
98+ }
99+ else if ( _this . deleteOnMatch )
100+ {
101+ _this . destroy ( ) ;
102+ }
103+ }
104+ } ;
105+
106+ this . onKeyDown = onKeyDownHandler ;
107+
108+ this . manager . events . on ( 'KEY_DOWN_EVENT' , onKeyDownHandler ) ;
71109} ;
72110
73111KeyCombo . prototype . constructor = KeyCombo ;
74112
75113KeyCombo . prototype = {
76114
115+ destroy : function ( )
116+ {
117+ this . enabled = false ;
118+ this . keyCodes = [ ] ;
77119
120+ this . manager . events . off ( 'KEY_DOWN' , this . onKeyDown ) ;
121+ this . manager = undefined ;
122+ }
78123
79124} ;
80125
0 commit comments