Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.thorstenschaefer.vm;
- import org.virtualbox_4_3.*;
- public class SendKeysToVm {
- private static final int keydown = 30;
- private static final int keyup = -98;
- public static void main(String[] args) {
- VirtualBoxManager mgr = VirtualBoxManager.createInstance(null);
- IVirtualBox vbox = mgr.getVBox();
- ISession session = mgr.getSessionObject();
- IMachine machine = vbox.getMachines().get(0);
- if (machine == null) {
- System.out.println("Machine not found");
- System.exit(1);
- }
- System.out.println("VM: " + machine.getName());
- machine.lockMachine(session, LockType.Shared);
- IConsole console = session.getConsole();
- IKeyboard keyboard = console.getKeyboard();
- System.out.println("Sending key strokes (a)");
- for (int i=0; i<1000; i++) {
- long start = System.currentTimeMillis();
- keyboard.putScancode(keydown);
- keyboard.putScancode(keyup);
- long end = System.currentTimeMillis();
- System.out.println("Click " + i + ": " + (end - start));
- }
- System.out.println("End sending keystrokes");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement