101 ! |
101 ! |
102 |
102 |
103 examples |
103 examples |
104 " |
104 " |
105 catch an enterfields input: |
105 catch an enterfields input: |
106 |
106 [exBegin] |
107 |top field forwarder catcher| |
107 |top field forwarder catcher| |
108 |
108 |
109 catcher := Plug new. |
109 catcher := Plug new. |
110 catcher respondTo:#keyPress:x:y:view: |
110 catcher respondTo:#keyPress:x:y:view: |
111 with:[:key :x :y :view | Transcript showCr:'cought keyPress: ' , key printString.]. |
111 with:[:key :x :y :view | Transcript showCr:'cought keyPress: ' , key printString.]. |
112 catcher respondTo:#keyRelease:x:y:view: |
112 catcher respondTo:#keyRelease:x:y:view: |
113 with:[:key :x :y :view | Transcript showCr:'cought keyRelease: ' , key printString.]. |
113 with:[:key :x :y :view | Transcript showCr:'cought keyRelease: ' , key printString.]. |
114 |
114 |
115 top := StandardSystemView new. |
115 top := StandardSystemView new. |
116 top extent:200@200. |
116 top extent:200@200. |
117 |
117 |
118 field := EditField in:top. |
118 field := EditField in:top. |
119 field origin:0.0@0.0; width:1.0. |
119 field origin:0.0@0.0; width:1.0. |
120 |
120 |
121 forwarder := KeyboardForwarder to:catcher. |
121 forwarder := KeyboardForwarder to:catcher. |
122 field delegate:forwarder. |
122 field delegate:forwarder. |
123 |
123 |
124 top open |
124 top open |
|
125 [exEnd] |
125 |
126 |
126 |
127 |
127 catch an enterfields return-key only: |
128 catch an enterfields return-key only: |
128 |
129 [exBegin] |
129 |top field forwarder catcher| |
130 |top field forwarder catcher| |
130 |
131 |
131 catcher := Plug new. |
132 catcher := Plug new. |
132 catcher respondTo:#keyPress:x:y:view: |
133 catcher respondTo:#keyPress:x:y:view: |
133 with:[:key :x :y :view | Transcript showCr:'cought return']. |
134 with:[:key :x :y :view | Transcript showCr:'cought return']. |
134 |
135 |
135 top := StandardSystemView new. |
136 top := StandardSystemView new. |
136 top extent:200@200. |
137 top extent:200@200. |
137 |
138 |
138 field := EditField in:top. |
139 field := EditField in:top. |
139 field origin:0.0@0.0; width:1.0. |
140 field origin:0.0@0.0; width:1.0. |
140 |
141 |
141 forwarder := KeyboardForwarder |
142 forwarder := KeyboardForwarder |
142 to:catcher |
143 to:catcher |
143 condition:[:type :key :view | (type == #keyPress) & (key == #Return)]. |
144 condition:[:type :key :view | (type == #keyPress) & (key == #Return)]. |
144 field delegate:forwarder. |
145 field delegate:forwarder. |
145 |
146 |
146 top open |
147 top open |
|
148 [exEnd] |
147 |
149 |
148 |
150 |
149 catch all of an enterfields input and ignore it: |
151 catch all of an enterfields input and ignore it: |
150 |
152 [exBegin] |
151 |top field forwarder| |
153 |top field forwarder| |
152 |
154 |
153 top := StandardSystemView new. |
155 top := StandardSystemView new. |
154 top extent:200@200. |
156 top extent:200@200. |
155 |
157 |
156 field := EditField in:top. |
158 field := EditField in:top. |
157 field origin:0.0@0.0; width:1.0. |
159 field origin:0.0@0.0; width:1.0. |
158 |
160 |
159 forwarder := KeyboardForwarder to:nil. |
161 forwarder := KeyboardForwarder to:nil. |
160 field delegate:forwarder. |
162 field delegate:forwarder. |
161 |
163 |
162 top open |
164 top open |
|
165 [exEnd] |
163 " |
166 " |
164 ! ! |
167 ! ! |
165 |
168 |
166 !KeyboardForwarder class methodsFor:'instance creation'! |
169 !KeyboardForwarder class methodsFor:'instance creation'! |
167 |
170 |