Exemplo n.º 1
0
        public InputMapper(VncClient client, Image image)
        {
            this.client = client;
            Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
            Window.Current.CoreWindow.KeyUp   += CoreWindow_KeyUp;
            Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated;

            charMap = new Dictionary <VirtualKey, Tuple <uint, uint> >();
            for (var i = 0; i < 26; ++i)
            {
                AddChar(VirtualKey.A + i, 'A' + i, 'a' + i);
            }
            string symbols = ")!@#$%^&*(";

            for (var i = 0; i < 10; ++i)
            {
                AddChar(VirtualKey.Number0 + i, symbols[i], '0' + i);
            }
            AddChar(219, '{', '[');
            AddChar(221, '}', ']');
            AddChar(186, ':', ';');
            AddChar(187, '+', '=');
            AddChar(188, '<', ',');
            AddChar(189, '_', '-');
            AddChar(190, '>', '.');
            AddChar(191, '?', '/');
            AddChar(192, '~', '`');
            AddChar(220, '|', '\\');
            AddChar(222, '"', '\'');

            specialMap = new Dictionary <VirtualKey, uint>();
            AddSpecial(VirtualKey.Enter, 0xFF0D);
            AddSpecial(VirtualKey.Space, ' ');
            AddSpecial(VirtualKey.Back, 0xFF08);
            AddSpecial(VirtualKey.Tab, 0xFF09);
            AddSpecial(VirtualKey.Escape, 0xFF1B);

            AddSpecial(VirtualKey.Left, 0xFF51);
            AddSpecial(VirtualKey.Up, 0xFF52);
            AddSpecial(VirtualKey.Right, 0xFF53);
            AddSpecial(VirtualKey.Down, 0xFF54);

            AddSpecial(VirtualKey.PageUp, 0xFF55);
            AddSpecial(VirtualKey.PageDown, 0xFF56);
            AddSpecial(VirtualKey.End, 0xFF57);
            AddSpecial(VirtualKey.Home, 0xFF58);

            AddSpecial(VirtualKey.Shift, 0xFFE1);
            AddSpecial(VirtualKey.LeftShift, 0xFFE1);
            AddSpecial(VirtualKey.RightShift, 0xFFE2);
            AddSpecial(VirtualKey.Control, 0xFFE3);
            AddSpecial(VirtualKey.LeftControl, 0xFFE3);
            AddSpecial(VirtualKey.RightControl, 0xFFE4);
            AddSpecial(VirtualKey.Menu, 0xFFE9);
            AddSpecial(VirtualKey.LeftMenu, 0xFFE9);
            AddSpecial(VirtualKey.RightMenu, 0xFFEA);
            AddSpecial(VirtualKey.LeftWindows, 0xFFE7);
            AddSpecial(VirtualKey.RightWindows, 0xFFE8);
        }
Exemplo n.º 2
0
        protected override void OnNavigatedTo(NavigationEventArgs ne)
        {
            base.OnNavigatedTo(ne);
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            var host = (Host)ne.Parameter;

            client = new VncClient(host.Hostname, host.Port, host.Password);
            mapper = new InputMapper(client, image);

            image.PointerMoved += (sender, e) => {
                HandlePointer(e.GetCurrentPoint(image));
                e.Handled = true;
            };
            image.PointerPressed += (sender, e) => {
                HandlePointer(e.GetCurrentPoint(image));
                e.Handled = true;
            };
            image.PointerReleased += (sender, e) => {
                HandlePointer(e.GetCurrentPoint(image));
                e.Handled = true;
            };
            image.PointerWheelChanged += (sender, e) => {
                HandlePointer(e.GetCurrentPoint(image));
                e.Handled = true;
            };

            var             dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
            WriteableBitmap wb         = null;

            client.Updated += async(sender, e) => {
                await dispatcher.RunAsync(CoreDispatcherPriority.High, new DispatchedHandler(() => {
                    if (wb == null || wb.PixelWidth != e.fbw || wb.PixelHeight != e.fbh)
                    {
                        wb = new WriteableBitmap(e.fbw, e.fbh);
                    }
                    using (var stream = wb.PixelBuffer.AsStream())
                        stream.Write(e.fb, 0, e.fb.Length);
                    wb.Invalidate();
                    image.Source = wb;
                }));
            };

            client.Resized += async(sender, e) => {
                ratio = (float)e.Width / e.Height;

                await dispatcher.RunAsync(CoreDispatcherPriority.High, new DispatchedHandler(() => {
                    ResizeWindow();
                }));
            };
            var aview = ApplicationView.GetForCurrentView();

            aview.VisibleBoundsChanged += Aview_VisibleBoundsChanged;

            client.Disconnected += async(sender, error) => {
                await dispatcher.RunAsync(CoreDispatcherPriority.High, new DispatchedHandler(async() => {
                    aview.VisibleBoundsChanged -= Aview_VisibleBoundsChanged;
                    mapper.Disconnect();
                    mapper = null;
                    client = null;
                    if (error)
                    {
                        var rootFrame = Window.Current.Content as Frame;
                        rootFrame.GoBack();
                        var dialog = new MessageDialog("You have been disconnected from the host");
                        dialog.Commands.Add(new UICommand("Close")
                        {
                            Id = 0
                        });
                        dialog.DefaultCommandIndex = 0;
                        dialog.CancelCommandIndex = 0;

                        await dialog.ShowAsync();
                    }
                }));
            };

            client.Bailed += async(sender, message) => {
                client.Disconnect();
                await dispatcher.RunAsync(CoreDispatcherPriority.High, new DispatchedHandler(async() => {
                    var rootFrame = Window.Current.Content as Frame;
                    rootFrame.GoBack();
                    var dialog = new MessageDialog(message, "You have been disconnected from the host");
                    dialog.Commands.Add(new UICommand("Close")
                    {
                        Id = 0
                    });
                    dialog.DefaultCommandIndex = 0;
                    dialog.CancelCommandIndex = 0;

                    await dialog.ShowAsync();
                }));
            };

            client.Connect();
        }