Changeset 27919 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Mar 31, 2010 6:12:14 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
r27906 r27919 1232 1232 return 0 1233 1233 1234 # PC XT scancodes 1235 scancodes = { 1236 'a': 0x1e, 1237 'b': 0x30, 1238 'c': 0x2e, 1239 'd': 0x20, 1240 'e': 0x12, 1241 'f': 0x21, 1242 'g': 0x22, 1243 'h': 0x23, 1244 'i': 0x17, 1245 'j': 0x24, 1246 'k': 0x25, 1247 'l': 0x26, 1248 'm': 0x32, 1249 'n': 0x31, 1250 'o': 0x18, 1251 'p': 0x19, 1252 'q': 0x10, 1253 'r': 0x13, 1254 's': 0x1f, 1255 't': 0x14, 1256 'u': 0x16, 1257 'v': 0x2f, 1258 'w': 0x11, 1259 'x': 0x2d, 1260 'y': 0x15, 1261 'z': 0x2c, 1262 '0': 0x0b, 1263 '1': 0x02, 1264 '2': 0x03, 1265 '3': 0x04, 1266 '4': 0x05, 1267 '5': 0x06, 1268 '6': 0x07, 1269 '7': 0x08, 1270 '8': 0x09, 1271 '9': 0x0a, 1272 ' ': 0x39, 1273 '-': 0xc, 1274 '=': 0xd, 1275 '[': 0x1a, 1276 ']': 0x1b, 1277 ';': 0x27, 1278 '\'': 0x28, 1279 ',': 0x33, 1280 '.': 0x34, 1281 '/': 0x35, 1282 '\t': 0xf, 1283 '\n': 0x1c, 1284 '`': 0x29 1285 }; 1286 1287 extScancodes = { 1288 'ESC' : [0x01], 1289 'BKSP': [0xe], 1290 'SPACE': [0x39], 1291 'TAB': [0x0f], 1292 'CAPS': [0x3a], 1293 'ENTER': [0x1c], 1294 'LSHIFT': [0x2a], 1295 'RSHIFT': [0x36], 1296 'INS': [0xe0, 0x52], 1297 'DEL': [0xe0, 0x53], 1298 'END': [0xe0, 0x4f], 1299 'HOME': [0xe0, 0x47], 1300 'PGUP': [0xe0, 0x49], 1301 'PGDOWN': [0xe0, 0x51], 1302 'LGUI': [0xe0, 0x5b], # GUI, aka Win, aka Apple key 1303 'RGUI': [0xe0, 0x5c], 1304 'LCTR': [0x1d], 1305 'RCTR': [0xe0, 0x1d], 1306 'LALT': [0x38], 1307 'RALT': [0xe0, 0x38], 1308 'APPS': [0xe0, 0x5d], 1309 'F1': [0x3b], 1310 'F2': [0x3c], 1311 'F3': [0x3d], 1312 'F4': [0x3e], 1313 'F5': [0x3f], 1314 'F6': [0x40], 1315 'F7': [0x41], 1316 'F8': [0x42], 1317 'F9': [0x43], 1318 'F10': [0x44 ], 1319 'F11': [0x57], 1320 'F12': [0x58], 1321 'UP': [0xe0, 0x48], 1322 'LEFT': [0xe0, 0x4b], 1323 'DOWN': [0xe0, 0x50], 1324 'RIGHT': [0xe0, 0x4d], 1325 }; 1326 1327 def keyDown(ch): 1328 code = scancodes.get(ch, 0x0) 1329 if code != 0: 1330 return [code] 1331 extCode = extScancodes.get(ch, []) 1332 if len(extCode) == 0: 1333 print "bad ext",ch 1334 return extCode 1335 1336 def keyUp(ch): 1337 codes = keyDown(ch)[:] # make a copy 1338 if len(codes) > 0: 1339 codes[len(codes)-1] += 0x80 1340 return codes 1341 1342 def typeInGuest(console, text, delay): 1343 import time 1344 pressed = [] 1345 group = False 1346 modGroupEnd = True 1347 i = 0 1348 while i < len(text): 1349 ch = text[i] 1350 i = i+1 1351 if ch == '{': 1352 # start group, all keys to be pressed at the same time 1353 group = True 1354 continue 1355 if ch == '}': 1356 # end group, release all keys 1357 for c in pressed: 1358 console.keyboard.putScancodes(keyUp(c)) 1359 pressed = [] 1360 group = False 1361 continue 1362 if ch == '^' or ch == '|' or ch == '$' or ch == '_': 1363 if ch == '^': 1364 ch = 'LCTR' 1365 if ch == '|': 1366 ch = 'LSHIFT' 1367 if ch == '_': 1368 ch = 'LALT' 1369 if ch == '$': 1370 ch = 'LGUI' 1371 if not group: 1372 modGroupEnd = False 1373 else: 1374 if ch == '\\': 1375 if i < len(text): 1376 ch = text[i] 1377 i = i+1 1378 if ch == 'n': 1379 ch = '\n' 1380 elif ch == '&': 1381 combo = "" 1382 while i < len(text): 1383 ch = text[i] 1384 i = i+1 1385 if ch == ';': 1386 break 1387 combo += ch 1388 ch = combo 1389 modGroupEnd = True 1390 console.keyboard.putScancodes(keyDown(ch)) 1391 pressed.insert(0, ch) 1392 if not group and modGroupEnd: 1393 for c in pressed: 1394 console.keyboard.putScancodes(keyUp(c)) 1395 pressed = [] 1396 modGroupEnd = True 1397 time.sleep(delay) 1398 1399 def typeGuestCmd(ctx, args): 1400 import sys 1401 1402 if len(args) < 3: 1403 print "usage: typeGuest <machine> <text> <charDelay>" 1404 return 0 1405 mach = ctx['machById'](args[1]) 1406 if mach is None: 1407 return 0 1408 1409 text = args[2] 1410 1411 if len(args) > 3: 1412 delay = float(args[3]) 1413 else: 1414 delay = 0.1 1415 1416 args = [lambda ctx,mach,console,args: typeInGuest(console, text, delay)] 1417 cmdExistingVm(ctx, mach, 'guestlambda', args) 1418 1419 return 0 1420 1421 1234 1422 aliases = {'s':'start', 1235 1423 'i':'info', … … 1238 1426 'a':'alias', 1239 1427 'q':'quit', 'exit':'quit', 1428 'tg': 'typeGuest', 1240 1429 'v':'verbose'} 1241 1430 … … 1270 1459 'screenshot':['Take VM screenshot to a file: screenshot Win /tmp/win.png 1024 768', screenshotCmd, 0], 1271 1460 'teleport':['Teleport VM to another box (see openportal): teleport Win anotherhost:8000 <passwd> <maxDowntime>', teleportCmd, 0], 1461 'typeGuest':['Type arbitrary text in guest: typeGuest Linux "^lls\\n&UP;&BKSP;ess /etc/hosts\\nq^c" 0.7', typeGuestCmd, 0], 1272 1462 'openportal':['Open portal for teleportation of VM from another box (see teleport): openportal Win 8000 <passwd>', openportalCmd, 0], 1273 1463 'closeportal':['Close teleportation portal (see openportal,teleport): closeportal Win', closeportalCmd, 0], … … 1439 1629 'argsToMach': lambda args: argsToMach(ctx,args), 1440 1630 'progressBar': lambda p: progressBar(ctx,p), 1631 'typeInGuest': typeInGuest, 1441 1632 '_machlist':None 1442 1633 }
Note:
See TracChangeset
for help on using the changeset viewer.