Bonjour,
j'aimerai réaliser un traitement lorsque l'utilisateur clique sur CONTROL + c
par exemple ....
ceci ne marche pas...
Code:
1
2
3
4 if (Key.isDown(Key.CONTROL) && Key.getCode() == "67") { trace("youhou"); }
Version imprimable
Bonjour,
j'aimerai réaliser un traitement lorsque l'utilisateur clique sur CONTROL + c
par exemple ....
ceci ne marche pas...
Code:
1
2
3
4 if (Key.isDown(Key.CONTROL) && Key.getCode() == "67") { trace("youhou"); }
je veux juste comprendre comment on pourrait réaliser un raccourcis clavier composé d'une combinaison de touche : CTRL + m par exemple...
faut-il mettre un timer
pourquoi ceci ne fonctionne pas :
Code:
1
2
3
4
5
6
7 if (Key.isDown(Key.CONTROL)) { var k = Key.getCode(); if (String.fromCharCode(k) == "m"){ trace("CTRL+m pressed!"); } }
un timer non pas besoin avec flash8.. mais faut que tu stockes à l'avance tes combinaisons de touches dans un tableau et à chaque fois que tu fais un keydown faut comparer dans l'ordre du tableau si la touche que tu viens de taper correspond à la prochaine case du tableau.... D'ou la notion d'un iterator (pattern utilisé par le framework java et que tu peux trouver un peu partout sur le net)
Exemple à analyser et à comprendre :
PS : pour tester dans flash faut pas oublier de désactiver les raccourcis clavier en bas du menu CONTROL du flashPlayer de flash :)Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169 /* ---------- Class ArrayIterator AUTHOR Name : ArrayIterator type : AS1 Package : vegas.data.array Version : 1.0.0.0 Author : ekameleon Date : 2005-06-01 METHODS - hasNext() - next() - remove() - current() - seek() - reset() - toString ---------- */ // ----o Constructor ArrayIterator = function ( ar ) { // ---- Private Properties this._a = ar ; this._k = -1 ; } var p = ArrayIterator.prototype ; // ---- Public Methods p.current = function() { return this._k ; } p.hasNext = function () { return (this._k < this._a.length -1) ; } p.next = function () { return this._a[++this._k] ; } p.reset = function() { this._k = -1 ; } p.remove = function() { this._a.splice(this._k--, 1) ; } p.seek = function (n) { var l = this._a.length ; if (n<-1) n=-1 ; else if (n> l) n = l ; this._k = n ; } p.toString = function () { return "[ArrayIterator]" ; } // ----o Encapsulate delete p ; trace ("++++ running ArrayIterator") ; /* ---------- Class KeysValidator AUTHOR Name : KeysValidator type : AS1 Package : vegas.ui Version : 1.0.0.0 Author : ekameleon Date : 2005-12-04 METHODS - clear() - countKeys() - insert() - reset() - supports(value) - toString() - toString - validate(value) ---------- */ // ----o Constructor KeysValidator = function ( keys:Array ) { this._keys = [].concat(keys) ; this.reset() ; this._listeners = [] ; // MIXIN Asbroadcaster event model Key.addListener(this) ; } var p = KeysValidator.prototype ; AsBroadcaster.initialize(p) ; // MIXIN AsBroadcaster event model // ----o Public MEthods p.clear = function():Void { this._keys = [] ; } p.countKeys = function ():Number { return this._keys.length ; } p.insert = function(keyCode:Number):Void { this._keys.push(keyCode) ; } p.reset = function () { this.it = new ArrayIterator(this._keys) ; } p.supports = function (value):Boolean { return this.it.next() == value ; } p.toString = function():String { return "[KeysValidator]" ; } p.validate = function (value):Void { if ( this.supports(value) ) { if (!this.it.hasNext()) { this.reset() ; this.broadcastMessage("valid") ; } } else { this.reset() ; this.broadcastMessage("invalid") ; } } // ----o Private Methods p.onKeyDown = function ():Void { this.validate(Key.getCode()) ; } var keys = [Key.CONTROL , 68 ] ; // CTRL + C // ---- test d'utilisation d'un ArrayIterator var it = new ArrayIterator(keys) ; while (it.hasNext()) { trace ("--> " + it.next()) ; } // ---- test d'utilisation du KeysValidator var valid = function () { trace ("valid") ; } var invalid = function () { trace ("invalid") ; } var validator = new KeysValidator( keys ) ; validator.addListener(this) ;
EKA+ :)