- Timestamp:
- Oct 20, 2010 2:35:22 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
r33204 r33266 371 371 if listener and registered: 372 372 es.unregisterListener(listener) 373 374 375 tsLast = 0 376 def recordDemo(ctx, console, file, dur): 377 demo = open(file, 'w') 378 header="VM="+console.machine.name+"\n" 379 demo.write(header) 380 381 global tsLast 382 tsLast = time.time() 383 384 def stamp(): 385 global tsLast 386 tsCur = time.time() 387 rv = int((tsCur-tsLast)*1000) 388 tsLast = tsCur 389 return rv 390 391 def handleEventImpl(ev): 392 type = ev.type 393 #print "got event: %s %s" %(str(type), asEnumElem(ctx, 'VBoxEventType', type)) 394 if type == ctx['global'].constants.VBoxEventType_OnGuestMouseEvent: 395 mev = ctx['global'].queryInterface(ev, 'IGuestMouseEvent') 396 if mev: 397 l = "%d: m %d %d %d %d %d %d\n" %(stamp(), mev.absolute, mev.x, mev.y, mev.z, mev.w, mev.buttons) 398 demo.write(l) 399 elif type == ctx['global'].constants.VBoxEventType_OnGuestKeyboardEvent: 400 kev = ctx['global'].queryInterface(ev, 'IGuestKeyboardEvent') 401 if kev: 402 l = "%d: k %s\n" %(stamp(), str(ctx['global'].getArray(kev, 'scancodes'))) 403 demo.write(l) 404 405 listener = console.eventSource.createListener() 406 registered = False 407 sources = [console.keyboard.eventSource, console.mouse.eventSource] 408 demo = open(file, 'w') 409 header="VM="+console.machine.name+"\n" 410 demo.write(header) 411 if dur == -1: 412 # not infinity, but close enough 413 dur = 100000 414 try: 415 for es in sources: 416 es.registerListener(listener, [ctx['global'].constants.VBoxEventType_Any], False) 417 registered = True 418 end = time.time() + dur 419 while time.time() < end: 420 for es in sources: 421 ev = es.getEvent(listener, 0) 422 if ev: 423 handleEventImpl(ev) 424 # keyboard/mouse events aren't waitable, so no need for eventProcessed 425 # We need to catch all exceptions here, otherwise listener will never be unregistered 426 except: 427 traceback.print_exc() 428 pass 429 demo.close() 430 if listener and registered: 431 for es in sources: 432 es.unregisterListener(listener) 433 434 435 def playbackDemo(ctx, console, file, dur): 436 demo = open(file, 'r') 437 438 if dur == -1: 439 # not infinity, but close enough 440 dur = 100000 441 442 header = demo.readline() 443 print "Header is", header 444 basere = re.compile(r'(?P<s>\d+): (?P<t>[km]) (?P<p>.*)') 445 mre = re.compile(r'(?P<a>\d+) (?P<x>\d+) (?P<y>\d+) (?P<z>\d+) (?P<w>\d+) (?P<b>\d+)') 446 kre = re.compile(r'\d+') 447 448 kbd = console.keyboard 449 mouse = console.mouse 450 451 try: 452 end = time.time() + dur 453 while time.time() < end: 454 for line in demo: 455 m = basere.search(line) 456 if m is not None: 457 dict = m.groupdict() 458 stamp = dict['s'] 459 params = dict['p'] 460 type = dict['t'] 461 462 time.sleep(float(stamp)/1000) 463 464 if type == 'k': 465 codes=kre.findall(params) 466 #print "KBD:",codes 467 kbd.putScancodes(codes) 468 elif type == 'm': 469 mm = mre.search(params) 470 if mm is not None: 471 mdict = mm.groupdict() 472 if mdict['a'] == '1': 473 # absolute 474 #print "MA: ",mdict['x'],mdict['y'],mdict['b'] 475 mouse.putMouseEventAbsolute(mdict['x'], mdict['y'], mdict['z'], mdict['w'], mdict['b']) 476 else: 477 #print "MR: ",mdict['x'],mdict['y'],mdict['b'] 478 mouse.putMouseEvent(mdict['x'], mdict['y'], mdict['z'], mdict['w'], mdict['b']) 479 480 # We need to catch all exceptions here, to close file 481 except: 482 traceback.print_exc() 483 pass 484 demo.close() 373 485 374 486 … … 1771 1883 modGroupEnd = True 1772 1884 i = 0 1885 kbd = console.keyboard 1773 1886 while i < len(text): 1774 1887 ch = text[i] … … 1781 1894 # end group, release all keys 1782 1895 for c in pressed: 1783 console.keyboard.putScancodes(keyUp(c))1896 kbd.putScancodes(keyUp(c)) 1784 1897 pressed = [] 1785 1898 group = False … … 1817 1930 ch = combo 1818 1931 modGroupEnd = True 1819 console.keyboard.putScancodes(keyDown(ch))1932 kbd.putScancodes(keyDown(ch)) 1820 1933 pressed.insert(0, ch) 1821 1934 if not group and modGroupEnd: 1822 1935 for c in pressed: 1823 console.keyboard.putScancodes(keyUp(c))1936 kbd.putScancodes(keyUp(c)) 1824 1937 pressed = [] 1825 1938 modGroupEnd = True … … 2833 2946 cmdargs[1] = m.id 2834 2947 runCommandArgs(ctx, cmdargs) 2948 return 0 2949 2950 def recordDemoCmd(ctx, args): 2951 if (len(args) < 3): 2952 print "usage: recordDemo vm filename (duration)" 2953 return 0 2954 mach = argsToMach(ctx,args) 2955 if mach == None: 2956 return 0 2957 filename = args[2] 2958 dur = 10000 2959 if len(args) > 3: 2960 dur = float(args[3]) 2961 cmdExistingVm(ctx, mach, 'guestlambda', [lambda ctx,mach,console,args: recordDemo(ctx, console, filename, dur)]) 2962 return 0 2963 2964 def playbackDemoCmd(ctx, args): 2965 if (len(args) < 3): 2966 print "usage: playbackDemo vm filename (duration)" 2967 return 0 2968 mach = argsToMach(ctx,args) 2969 if mach == None: 2970 return 0 2971 filename = args[2] 2972 dur = 10000 2973 if len(args) > 3: 2974 dur = float(args[3]) 2975 cmdExistingVm(ctx, mach, 'guestlambda', [lambda ctx,mach,console,args: playbackDemo(ctx, console, filename, dur)]) 2835 2976 return 0 2836 2977 … … 2916 3057 'foreachvm' : ['Perform command for each VM', foreachvmCmd, 0], 2917 3058 'foreach' : ['Generic "for each" construction, using XPath-like notation: foreach //vms/vm[@OSTypeId=\'MacOS\'] "print obj.name"', foreachCmd, 0], 3059 'recordDemo':['Record demo: recordDemo Win32 file.dmo 10', recordDemoCmd, 0], 3060 'playbackDemo':['Playback demo: playbackDemo Win32 file.dmo 10', playbackDemoCmd, 0] 2918 3061 } 2919 3062
Note:
See TracChangeset
for help on using the changeset viewer.