Mercurial > 510Connectbot
comparison src/de/mud/terminal/vt320.java @ 104:171e0a977544
cleanup keystroke handling
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 18 Jun 2014 10:10:14 -0700 |
parents | 8181cb01c64d |
children | 77ac18bc1b2f |
comparison
equal
deleted
inserted
replaced
103:1a34365fab9b | 104:171e0a977544 |
---|---|
942 | 942 |
943 return write(s, false); | 943 return write(s, false); |
944 } | 944 } |
945 | 945 |
946 /** | 946 /** |
947 * main keytyping event handler... | 947 * main keytyping event handler for all the special function and modifier keys |
948 * the normal keys are processed by write(byte b); | |
948 */ | 949 */ |
949 public void keyPressed(int keyCode, char keyChar, int modifiers) { | 950 public void keyPressed(int keyCode, char keyChar, int modifiers) { |
950 boolean control = (modifiers & VDUInput.KEY_CONTROL) != 0; | 951 boolean control = (modifiers & VDUInput.KEY_CONTROL) != 0; |
951 boolean shift = (modifiers & VDUInput.KEY_SHIFT) != 0; | 952 boolean shift = (modifiers & VDUInput.KEY_SHIFT) != 0; |
952 boolean alt = (modifiers & VDUInput.KEY_ALT) != 0; | 953 boolean alt = (modifiers & VDUInput.KEY_ALT) != 0; |
1110 case KEY_CONTROL: | 1111 case KEY_CONTROL: |
1111 case KEY_ALT: | 1112 case KEY_ALT: |
1112 break; | 1113 break; |
1113 | 1114 |
1114 case KEY_ESCAPE: | 1115 case KEY_ESCAPE: |
1115 write(0x1b); | 1116 writeSpecial(Escape[xind]); |
1116 break; | 1117 break; |
1117 | 1118 |
1118 case KEY_ENTER: | 1119 case KEY_ENTER: |
1119 write(0x0d); | 1120 write(0x0d); |
1120 break; | 1121 break; |
1121 | 1122 |
1122 case KEY_TAB: | 1123 case KEY_TAB: |
1123 write(0x09); | 1124 writeSpecial(TabKey[xind]); |
1124 break; | 1125 break; |
1125 | 1126 |
1126 default: | 1127 default: |
1127 break; | 1128 break; |
1128 } | |
1129 } | |
1130 /* | |
1131 public void keyReleased(KeyEvent evt) { | |
1132 if (debug > 1) debug("keyReleased("+evt+")"); | |
1133 // ignore | |
1134 } | |
1135 */ | |
1136 /** | |
1137 * Handle key Typed events for the terminal, this will get | |
1138 * all normal key types, but no shift/alt/control/numlock. | |
1139 */ | |
1140 public void keyTyped(int keyCode, char keyChar, int modifiers) { | |
1141 boolean control = (modifiers & VDUInput.KEY_CONTROL) != 0; | |
1142 boolean shift = (modifiers & VDUInput.KEY_SHIFT) != 0; | |
1143 boolean alt = (modifiers & VDUInput.KEY_ALT) != 0; | |
1144 | |
1145 if (debug > 1) debug("keyTyped(" + keyCode + ", " + (int)keyChar + ", " + modifiers + ")"); | |
1146 | |
1147 if (keyChar == '\t') { | |
1148 if (shift) { | |
1149 write(TabKey[1], false); | |
1150 } | |
1151 else { | |
1152 if (control) { | |
1153 write(TabKey[2], false); | |
1154 } | |
1155 else { | |
1156 if (alt) { | |
1157 write(TabKey[3], false); | |
1158 } | |
1159 else { | |
1160 write(TabKey[0], false); | |
1161 } | |
1162 } | |
1163 } | |
1164 | |
1165 return; | |
1166 } | |
1167 | |
1168 if (alt) { | |
1169 write(((char)(keyChar | 0x80))); | |
1170 return; | |
1171 } | |
1172 | |
1173 if (((keyCode == KEY_ENTER) || (keyChar == 10)) | |
1174 && !control) { | |
1175 write('\r'); | |
1176 | |
1177 if (localecho) putString("\r\n"); // bad hack | |
1178 | |
1179 return; | |
1180 } | |
1181 | |
1182 if ((keyCode == 10) && !control) { | |
1183 debug("Sending \\r"); | |
1184 write('\r'); | |
1185 return; | |
1186 } | |
1187 | |
1188 // FIXME: on german PC keyboards you have to use Alt-Ctrl-q to get an @, | |
1189 // so we can't just use it here... will probably break some other VMS | |
1190 // codes. -Marcus | |
1191 // if(((!vms && keyChar == '2') || keyChar == '@' || keyChar == ' ') | |
1192 // && control) | |
1193 if (((!vms && keyChar == '2') || keyChar == ' ') && control) | |
1194 write(0); | |
1195 | |
1196 if (vms) { | |
1197 if (keyChar == 127 && !control) { | |
1198 if (shift) | |
1199 writeSpecial(Insert[0]); // VMS shift delete = insert | |
1200 else | |
1201 writeSpecial(Remove[0]); // VMS delete = remove | |
1202 | |
1203 return; | |
1204 } | |
1205 else if (control) | |
1206 switch (keyChar) { | |
1207 case '0': | |
1208 writeSpecial(Numpad[0]); | |
1209 return; | |
1210 | |
1211 case '1': | |
1212 writeSpecial(Numpad[1]); | |
1213 return; | |
1214 | |
1215 case '2': | |
1216 writeSpecial(Numpad[2]); | |
1217 return; | |
1218 | |
1219 case '3': | |
1220 writeSpecial(Numpad[3]); | |
1221 return; | |
1222 | |
1223 case '4': | |
1224 writeSpecial(Numpad[4]); | |
1225 return; | |
1226 | |
1227 case '5': | |
1228 writeSpecial(Numpad[5]); | |
1229 return; | |
1230 | |
1231 case '6': | |
1232 writeSpecial(Numpad[6]); | |
1233 return; | |
1234 | |
1235 case '7': | |
1236 writeSpecial(Numpad[7]); | |
1237 return; | |
1238 | |
1239 case '8': | |
1240 writeSpecial(Numpad[8]); | |
1241 return; | |
1242 | |
1243 case '9': | |
1244 writeSpecial(Numpad[9]); | |
1245 return; | |
1246 | |
1247 case '.': | |
1248 writeSpecial(KPPeriod); | |
1249 return; | |
1250 | |
1251 case '-': | |
1252 case 31: | |
1253 writeSpecial(KPMinus); | |
1254 return; | |
1255 | |
1256 case '+': | |
1257 writeSpecial(KPComma); | |
1258 return; | |
1259 | |
1260 case 10: | |
1261 writeSpecial(KPEnter); | |
1262 return; | |
1263 | |
1264 case '/': | |
1265 writeSpecial(PF2); | |
1266 return; | |
1267 | |
1268 case '*': | |
1269 writeSpecial(PF3); | |
1270 return; | |
1271 | |
1272 /* NUMLOCK handled in keyPressed */ | |
1273 default: | |
1274 break; | |
1275 } | |
1276 | |
1277 /* Now what does this do and how did it get here. -Marcus | |
1278 if (shift && keyChar < 32) { | |
1279 write(PF1+(char)(keyChar + 64)); | |
1280 return; | |
1281 } | |
1282 */ | |
1283 } | |
1284 | |
1285 // FIXME: not used? | |
1286 //String fmap[]; | |
1287 int xind; | |
1288 xind = 0; | |
1289 | |
1290 //fmap = FunctionKey; | |
1291 if (shift) { | |
1292 //fmap = FunctionKeyShift; | |
1293 xind = 1; | |
1294 } | |
1295 | |
1296 if (control) { | |
1297 //fmap = FunctionKeyCtrl; | |
1298 xind = 2; | |
1299 } | |
1300 | |
1301 if (alt) { | |
1302 //fmap = FunctionKeyAlt; | |
1303 xind = 3; | |
1304 } | |
1305 | |
1306 if (keyCode == KEY_ESCAPE) { | |
1307 writeSpecial(Escape[xind]); | |
1308 return; | |
1309 } | |
1310 | |
1311 if ((modifiers & VDUInput.KEY_ACTION) != 0) | |
1312 switch (keyCode) { | |
1313 case KEY_NUMPAD0: | |
1314 writeSpecial(Numpad[0]); | |
1315 return; | |
1316 | |
1317 case KEY_NUMPAD1: | |
1318 writeSpecial(Numpad[1]); | |
1319 return; | |
1320 | |
1321 case KEY_NUMPAD2: | |
1322 writeSpecial(Numpad[2]); | |
1323 return; | |
1324 | |
1325 case KEY_NUMPAD3: | |
1326 writeSpecial(Numpad[3]); | |
1327 return; | |
1328 | |
1329 case KEY_NUMPAD4: | |
1330 writeSpecial(Numpad[4]); | |
1331 return; | |
1332 | |
1333 case KEY_NUMPAD5: | |
1334 writeSpecial(Numpad[5]); | |
1335 return; | |
1336 | |
1337 case KEY_NUMPAD6: | |
1338 writeSpecial(Numpad[6]); | |
1339 return; | |
1340 | |
1341 case KEY_NUMPAD7: | |
1342 writeSpecial(Numpad[7]); | |
1343 return; | |
1344 | |
1345 case KEY_NUMPAD8: | |
1346 writeSpecial(Numpad[8]); | |
1347 return; | |
1348 | |
1349 case KEY_NUMPAD9: | |
1350 writeSpecial(Numpad[9]); | |
1351 return; | |
1352 | |
1353 case KEY_DECIMAL: | |
1354 writeSpecial(NUMDot[xind]); | |
1355 return; | |
1356 | |
1357 case KEY_ADD: | |
1358 writeSpecial(NUMPlus[xind]); | |
1359 return; | |
1360 } | |
1361 | |
1362 if (!((keyChar == 8) || (keyChar == 127) || (keyChar == '\r') || (keyChar == '\n'))) { | |
1363 write(keyChar); | |
1364 return; | |
1365 } | 1129 } |
1366 } | 1130 } |
1367 | 1131 |
1368 private void handle_dcs(String dcs) { | 1132 private void handle_dcs(String dcs) { |
1369 debugStr.append("DCS: ") | 1133 debugStr.append("DCS: ") |