Advertisement
Guest User

Test program

a guest
Dec 26th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. package de.thorstenschaefer.vm;
  2.  
  3. import org.virtualbox_4_3.*;
  4.  
  5. public class SendKeysToVm {
  6.  
  7.     private static final int keydown = 30;
  8.     private static final int keyup = -98;
  9.    
  10.     public static void main(String[] args) {
  11.         VirtualBoxManager mgr = VirtualBoxManager.createInstance(null);
  12.         IVirtualBox vbox = mgr.getVBox();
  13.         ISession session = mgr.getSessionObject();
  14.         IMachine machine = vbox.getMachines().get(0);      
  15.  
  16.         if (machine == null) {
  17.             System.out.println("Machine not found");
  18.             System.exit(1);
  19.         }
  20.  
  21.         System.out.println("VM: " + machine.getName());
  22.         machine.lockMachine(session, LockType.Shared);
  23.         IConsole console = session.getConsole();
  24.         IKeyboard keyboard = console.getKeyboard();
  25.        
  26.         System.out.println("Sending key strokes (a)");
  27.         for (int i=0; i<1000; i++) {
  28.             long start = System.currentTimeMillis();
  29.             keyboard.putScancode(keydown);
  30.             keyboard.putScancode(keyup);
  31.             long end = System.currentTimeMillis();
  32.             System.out.println("Click " + i + ": " + (end - start));
  33.         }
  34.         System.out.println("End sending keystrokes");
  35.     }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement