Esempio n. 1
0
        public VirtualBoxControl(string name, int width, int height)
        {
            // boot
            Console.WriteLine("# booting vm");
            VirtualBox.VirtualBoxClass vbox = new VirtualBox.VirtualBoxClass();
            vm      = vbox.FindMachine(name);
            session = new VirtualBox.SessionClass();
            VirtualBox.IProgress progress = vbox.OpenRemoteSession(session, vm.Id, "gui", null);
            progress.WaitForCompletion(-1);
            vm.ShowConsoleWindow();

            // Wait
            while (vm.State != VirtualBox.MachineState.MachineState_Running)
            {
                Thread.Sleep(1000);
            }

            // buffer
            int x = 0, y = 0;

            session.Console.Display.GetFramebuffer((uint)0, out buffer, out x, out y);

            // disable mouse integration
            Thread.Sleep(3000);
            Console.WriteLine("disabling mouse integration");
            DisableMouseIntegration(name, width, height);
        }
Esempio n. 2
0
        public unsafe static void Main(string[] args)
        {
            VirtualBox.VirtualBoxClass vbox    = new VirtualBox.VirtualBoxClass();
            VirtualBox.IMachine        vm      = vbox.FindMachine("Poker Niklas");
            VirtualBox.Session         session = new VirtualBox.SessionClass();

            VirtualBox.IProgress progress = vbox.OpenRemoteSession(session, vm.Id, "gui", null);


            progress.WaitForCompletion(-1);


            //int x = 0, y = 0;
            //VirtualBox.IFramebuffer ori = null;
            //session.Console.Display.GetFramebuffer((uint)0, out ori, out x, out y);
            //VirtualBox.IFramebuffer buffer = new FrameBuffer(ori);
            //session.Console.Display.SetFramebuffer(0, buffer);

            vm.ShowConsoleWindow();

            Thread.Sleep(10 * 1000);

            IntPtr hwnd = FindWindowByCaption(IntPtr.Zero, "Poker Niklas [Running] - Sun VirtualBox");

            MoveWindow(hwnd, 0, 0, 1024 + 100, 768 + 100, false);
            Thread.Sleep(3 * 1000);

            /*Win32Control control = new Win32Control();
             * control.MouseMoveTo(45, 45);
             * control.MouseLeftClick();
             * control.MouseMoveTo(45, 160);
             * control.MouseLeftClick();
             *
             * Thread.Sleep(20 * 1000);
             * Console.WriteLine("reset");
             * control.ResetMouse();
             *
             * Console.WriteLine("reset done");
             * Thread.Sleep(20 * 1000);*/


            /*int x = 0, y = 0;
             * VirtualBox.IFramebuffer buf = null;
             * session.Console.Display.GetFramebuffer((uint)0, out buf, out x, out y);
             *
             *
             *
             *
             * CaptureWindow((IntPtr)buf.WinId).Save("test.bmp");*/

            Console.WriteLine("events");

            //session.Console.Mouse.PutMouseEvent(100, 100, 0, 0);

            /*Thread.Sleep(30 * 1000);
             * for (int i = 51; i <= 52; i++)
             * {
             *  Console.WriteLine(i);
             *  session.Console.Keyboard.PutScancode(i);
             *  Thread.Sleep(2000);
             * }*/
            Thread.Sleep(5 * 1000);
            for (int i = 20; i <= 40; i++)
            {
                Console.WriteLine(i);
                session.Console.Keyboard.PutScancode(i);
                Thread.Sleep(2000);
            }
            Thread.Sleep(30 * 1000);
            session.Console.SaveState();



            /*
             * int[] pixels = new int[128*128];
             * int pos = 0;
             * {
             *  buf.Lock();
             *  byte* ptr = (byte*)buf.Address.ToPointer();
             *  for (int i = 0; i < pixels.Length; i++)
             *   {
             *
             *            byte b1 = (*ptr);
             *             ptr++;
             *             byte b2 = (*ptr);
             *             ptr++;
             *             byte b3 = (*ptr);
             *             ptr++;
             *             byte b4 = (*ptr);
             *             ptr++;
             *             int pixel = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
             *             pixels[pos++] = BitConverter.ToInt32(new byte[] {b1, b2, b3, b4}, 0);
             *
             *   }
             *  buf.Unlock();
             *
             * }
             *
             * ImageTools.toBitmap(new Image(pixels, 128, 128), PixelFormat.Format32bppRgb).Save("test.bmp");
             * Console.WriteLine("done");
             */
            //Console.ReadKey();

            //session.Console.Mouse.PutMouseEvent(100, 100, 0, 0);

            //Console.ReadKey();


            //byte[] buf = new byte[session.Console.Display.Width * session.Console.Display.Height * 1000];
            //session.Console.Display.TakeScreenShot(ref buf[0], (uint)session.Console.Display.Width, (uint)session.Console.Display.Height);

            //Console.ReadKey();
        }