21
21
import javax .sound .sampled .AudioSystem ;
22
22
import javax .sound .sampled .Clip ;
23
23
import java .awt .*;
24
- import java .awt .event .KeyEvent ;
25
24
import java .io .IOException ;
25
+ import java .util .Collection ;
26
26
import java .util .logging .Level ;
27
27
import java .util .logging .Logger ;
28
28
29
+ import static java .awt .event .KeyEvent .*;
30
+
29
31
/**
30
32
* Created by breandan on 10/23/2015.
31
33
*/
@@ -54,6 +56,7 @@ public ASRControlLoop(CustomLiveSpeechRecognizer recognizer) {
54
56
public static final String SHRINK = "shrink" ;
55
57
public static final String PRESS = "press" ;
56
58
public static final String DELETE = "delete" ;
59
+ public static final String DEBUG = "debug" ;
57
60
public static final String ENTER = "enter" ;
58
61
public static final String ESCAPE = "escape" ;
59
62
public static final String TAB = "tab" ;
@@ -105,6 +108,7 @@ private String getResultFromRecognizer() {
105
108
logger .info ("\t Top H: " + result .getResult () + " / " + result .getResult ().getBestToken () + " / " + result .getResult ().getBestPronunciationResult ());
106
109
logger .info ("\t Top 3H: " + result .getNbest (3 ));
107
110
111
+ Collection <String > c = result .getNbest (3 );
108
112
return result .getHypothesis ();
109
113
}
110
114
@@ -119,7 +123,7 @@ private void applyAction(String c) {
119
123
} else if (c .endsWith (RECENT )) {
120
124
ideService .invokeAction (IdeActions .ACTION_RECENT_FILES );
121
125
} else if (c .endsWith (TERMINAL )) {
122
- pressKeystroke (KeyEvent . VK_ALT , KeyEvent . VK_F12 );
126
+ pressKeystroke (VK_ALT , VK_F12 );
123
127
}
124
128
} else if (c .startsWith (NAVIGATE )) {
125
129
ideService .invokeAction ("GotoDeclaration" );
@@ -130,53 +134,67 @@ private void applyAction(String c) {
130
134
ideService .invokeAction ("Idear.WhereAmI" );
131
135
} else if (c .startsWith ("focus" )) {
132
136
if (c .endsWith (EDITOR )) {
133
- pressKeystroke (KeyEvent . VK_ESCAPE );
137
+ pressKeystroke (VK_ESCAPE );
134
138
} else if (c .endsWith (PROJECT )) {
135
- pressKeystroke (KeyEvent . VK_ALT , KeyEvent . VK_1 );
139
+ pressKeystroke (VK_ALT , VK_1 );
136
140
} else if (c .endsWith ("symbols" )) {
137
141
ideService .invokeAction ("AceJumpAction" );
142
+ ideService .type (VK_SPACE );
138
143
ideService .type (("" + recognizeNumber ()).toCharArray ());
139
144
}
145
+ } else if (c .startsWith (GOTO )) {
146
+
140
147
} else if (c .startsWith (EXPAND )) {
141
- pressKeystroke (KeyEvent .VK_CONTROL , KeyEvent .VK_W );
148
+ // ActionManager instance = ActionManager.getInstance();
149
+ // AnAction a = instance.getAction("EditorSelectWord");
150
+ // AnActionEvent event = new AnActionEvent(null, DataManager.getInstance().getDataContext(),
151
+ // ActionPlaces.UNKNOWN, a.getTemplatePresentation(), instance, 0);
152
+ // a.actionPerformed(event);
153
+ ideService .invokeAction ("EditorSelectWord" );
142
154
} else if (c .startsWith (SHRINK )) {
143
- pressKeystroke (KeyEvent . VK_CONTROL , KeyEvent . VK_SHIFT , KeyEvent . VK_W );
155
+ pressKeystroke (VK_CONTROL , VK_SHIFT , VK_W );
144
156
} else if (c .startsWith ("press" )) {
145
157
if (c .contains ("delete" )) {
146
- pressKeystroke (KeyEvent . VK_DELETE );
147
- } else if (c .contains ("return" )) {
148
- pressKeystroke (KeyEvent . VK_ENTER );
158
+ pressKeystroke (VK_DELETE );
159
+ } else if (c .contains ("return" ) || c . contains ( "enter" ) ) {
160
+ pressKeystroke (VK_ENTER );
149
161
} else if (c .contains (ESCAPE )) {
150
- pressKeystroke (KeyEvent . VK_ESCAPE );
162
+ pressKeystroke (VK_ESCAPE );
151
163
} else if (c .contains (TAB )) {
152
- pressKeystroke (KeyEvent . VK_TAB );
164
+ pressKeystroke (VK_TAB );
153
165
} else if (c .contains (UNDO )) {
154
- pressKeystroke (KeyEvent . VK_CONTROL , KeyEvent . VK_Z );
166
+ pressKeystroke (VK_CONTROL , VK_Z );
155
167
}
156
168
} else if (c .startsWith ("following" )) {
157
169
if (c .endsWith ("line" )) {
158
- pressKeystroke (KeyEvent . VK_DOWN );
170
+ pressKeystroke (VK_DOWN );
159
171
} else if (c .endsWith ("page" )) {
160
- pressKeystroke (KeyEvent . VK_PAGE_DOWN );
172
+ pressKeystroke (VK_PAGE_DOWN );
161
173
} else if (c .endsWith ("method" )) {
162
- pressKeystroke (KeyEvent .VK_ALT , KeyEvent .VK_DOWN );
174
+ pressKeystroke (VK_ALT , VK_DOWN );
175
+ } else if (c .endsWith ("tab" )) {
176
+ pressKeystroke (VK_CONTROL , VK_TAB );
177
+ } else if (c .endsWith ("page" )) {
178
+ pressKeystroke (VK_PAGE_DOWN );
163
179
}
164
180
} else if (c .startsWith ("previous" )) {
165
181
if (c .endsWith ("line" )) {
166
- pressKeystroke (KeyEvent . VK_UP );
182
+ pressKeystroke (VK_UP );
167
183
} else if (c .endsWith ("page" )) {
168
- pressKeystroke (KeyEvent . VK_PAGE_UP );
184
+ pressKeystroke (VK_PAGE_UP );
169
185
} else if (c .endsWith ("method" )) {
170
- pressKeystroke (KeyEvent .VK_ALT , KeyEvent .VK_UP );
186
+ pressKeystroke (VK_ALT , VK_UP );
187
+ } else if (c .endsWith ("page" )) {
188
+ pressKeystroke (VK_PAGE_UP );
171
189
}
172
190
} else if (c .startsWith ("extract this" )) {
173
191
if (c .endsWith ("method" )) {
174
- pressKeystroke (KeyEvent . VK_CONTROL , KeyEvent . VK_ALT , KeyEvent . VK_M );
192
+ pressKeystroke (VK_CONTROL , VK_ALT , VK_M );
175
193
} else if (c .endsWith ("parameter" )) {
176
- pressKeystroke (KeyEvent . VK_CONTROL , KeyEvent . VK_ALT , KeyEvent . VK_P );
194
+ pressKeystroke (VK_CONTROL , VK_ALT , VK_P );
177
195
}
178
196
} else if (c .startsWith ("inspect code" )) {
179
- pressKeystroke (KeyEvent . VK_ALT , KeyEvent . VK_SHIFT , KeyEvent . VK_I );
197
+ pressKeystroke (VK_ALT , VK_SHIFT , VK_I );
180
198
} else if (c .startsWith ("speech pause" )) {
181
199
pauseSpeech ();
182
200
} else if (c .startsWith (OK_IDEA ) || c .startsWith (OKAY_IDEA )) {
@@ -187,16 +205,22 @@ private void applyAction(String c) {
187
205
fireGoogleSearch ();
188
206
} else if (c .contains ("break point" )) {
189
207
if (c .startsWith ("toggle" )) {
190
- pressKeystroke (KeyEvent . VK_CONTROL , KeyEvent . VK_F8 );
208
+ pressKeystroke (VK_CONTROL , VK_F8 );
191
209
} else if (c .startsWith ("view" )) {
192
- pressKeystroke (KeyEvent . VK_CONTROL , KeyEvent . VK_SHIFT , KeyEvent . VK_F8 );
210
+ pressKeystroke (VK_CONTROL , VK_SHIFT , VK_F8 );
193
211
}
212
+ } else if (c .startsWith ("debug" )){
213
+ pressKeystroke (VK_SHIFT , VK_F9 );
194
214
} else if (c .startsWith ("step" )) {
195
215
if (c .endsWith ("over" )) {
196
- pressKeystroke (KeyEvent . VK_F8 );
216
+ pressKeystroke (VK_F8 );
197
217
} else if (c .endsWith ("into" )) {
198
- pressKeystroke (KeyEvent .VK_F7 );
218
+ pressKeystroke (VK_F7 );
219
+ } else if (c .endsWith ("return" )) {
220
+ pressKeystroke (VK_SHIFT , VK_F8 );
199
221
}
222
+ } else if (c .startsWith ("resume" )) {
223
+ pressKeystroke (VK_F9 );
200
224
} else if (c .startsWith ("tell me a joke" )) {
201
225
tellJoke ();
202
226
} else if (c .contains ("check" )) {
@@ -338,7 +362,7 @@ public static synchronized void beep() {
338
362
try {
339
363
Clip clip = AudioSystem .getClip ();
340
364
AudioInputStream inputStream = AudioSystem .getAudioInputStream (
341
- ASRServiceImpl .class .getResourceAsStream ("/com.jetbrains.idear/sounds/beep.wav" ));
365
+ ASRService .class .getResourceAsStream ("/com.jetbrains.idear/sounds/beep.wav" ));
342
366
clip .open (inputStream );
343
367
clip .start ();
344
368
} catch (Exception e ) {
0 commit comments