Exemplo n.º 1
0
        } // KeyReleased closing bracket

        // Metodo che gestisce la terminazione dell'invio di dati al server (invocato da KeyPressed)
        private void SendToServer(IAsyncResult a)
        {
            MyTabManagement s = (MyTabManagement)a.AsyncState;

            try
            {
                s.Stream.EndWrite(a);
            }
            catch (IOException)
            {
                ExceptionHandler.SendError(s);
            }
        }
Exemplo n.º 2
0
        // Funzione invocata dall'evento PreviewKeyDown (registrato da SendCommands_Start)
        // Cattura e registra i modificatori e il tasto premuto e li invia al server
        private void KeyPressed(object sender, KeyEventArgs e)
        {
            //estrae l'attuale app in focus dalla AppsInFocusBox
            AppInFocus appinfocus = AppsInFocusBox.SelectedItem as AppInFocus;

            //Controlla se l'app in focus è il client stesso (per evitare cicli infiniti)
            if (appinfocus.Name == System.AppDomain.CurrentDomain.FriendlyName || appinfocus == null)
            {
                e.Handled = true;
                return;
            }

            Key key;

            if (e.Key == Key.System)
            {
                key = e.SystemKey;
            }
            else
            {
                key = e.Key;
            }

            switch (key)
            {
            case Key.LeftShift:
            case Key.RightShift:
                mod.shift = 'y';
                e.Handled = true;
                break;

            case Key.LeftCtrl:
            case Key.RightCtrl:
                mod.ctrl  = 'y';
                e.Handled = true;
                break;

            case Key.LeftAlt:
            case Key.RightAlt:
                mod.alt   = 'y';
                e.Handled = true;
                break;

            default:
                break;
            } // Switch closing bracket

            // Nel caso in cui il tasto premuto non sia un modificatore
            if (e.Handled == false)
            {
                // Preparazione dei dati da inviare

                byte[] buffer = new byte[3 + sizeof(int)];          // Struttura che conterra  Modificatori + tasto
                buffer[0] = Convert.ToByte(mod.ctrl);
                buffer[1] = Convert.ToByte(mod.alt);
                buffer[2] = Convert.ToByte(mod.shift);

                int conv_key = KeyInterop.VirtualKeyFromKey(key);
                BitConverter.GetBytes(IPAddress.HostToNetworkOrder(conv_key)).CopyTo(buffer, 3);

                // Recupero l'applicazione che è in focus dall'elemento selezionato nella combobox

                // Se c'è almeno un app in focus, cerchiamo il tab o server a cui appartiene
                foreach (MyTabItem tab in TabItemList)
                {
                    if (tab.AppInFocus == appinfocus.Name)
                    {
                        MyTabManagement s = tab.Content as MyTabManagement;
                        if (s != null)
                        {
                            try
                            {
                                //invia i tasti sul socket relativo a questa tab (server)
                                s.Stream.BeginWrite(buffer, 0, 3 + sizeof(int), new AsyncCallback(SendToServer), s);
                            }
                            catch (IOException)
                            {
                                ExceptionHandler.SendError(s);
                            }
                        }
                    }
                }

                e.Handled = true;
            }
        } // KeyPressed closing bracket
Exemplo n.º 3
0
        /*
         * Metodo eseguito allo scatenarsi dell'evento PreviewKeyDown
         * Cattura e registra i modificatori che vengono premuti
         * Cattura e invia i tasti che vengono premuti
         */
        private void Client_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            // Il tasto ALT è un tasto di sistema
            Key key = (e.Key == Key.System ? e.SystemKey : e.Key);

            // Switch per gestire la pressione dei modificatori
            switch (key)
            {
            case Key.LeftShift:
            case Key.RightShift:
                modifier       = modifier | command_t.shift;
                shiftRect.Fill = new SolidColorBrush(Colors.DeepSkyBlue);
                e.Handled      = true;
                break;

            case Key.LeftCtrl:
            case Key.RightCtrl:
                modifier      = modifier | command_t.ctrl;
                ctrlRect.Fill = new SolidColorBrush(Colors.DeepSkyBlue);
                e.Handled     = true;
                break;

            case Key.LeftAlt:
            case Key.RightAlt:
                modifier     = modifier | command_t.alt;
                altRect.Fill = new SolidColorBrush(Colors.DeepSkyBlue);
                e.Handled    = true;
                break;

            default:
                break;
            }

            // Se l'evento non è stato gestito, si procede all'invio del tasto premuto
            if (!e.Handled)
            {
                // Preparazione dei dati da inviare
                int    convertedKey = KeyInterop.VirtualKeyFromKey(key);
                byte[] buffer       = new byte[1 + sizeof(int)];
                buffer[0] = (byte)modifier;
                BitConverter.GetBytes(IPAddress.HostToNetworkOrder(convertedKey)).CopyTo(buffer, 1);

                // Ottenimento dell'app in foreground a cui vogliamo inviare i comandi
                ForegroundApp focusedApp = foregroundBox.SelectedItem as ForegroundApp;
                if (focusedApp == null)
                {
                    e.Handled = true;
                    return;
                }

                // Ricerca dei tab aventi quest'app in foreground
                foreach (InteractiveTabItem tab in tabItems)
                {
                    if (tab.foregroundApp == focusedApp.Name)
                    {
                        MyTabItem myTab = tab.Content as MyTabItem;
                        if (myTab != null)
                        {
                            // Invio asincrono dei dati
                            try {
                                myTab.Stream.BeginWrite(buffer, 0, 1 + sizeof(int), new AsyncCallback(SendToServer), myTab);
                            } catch (IOException) {
                                ExceptionHandler.SendError(myTab);
                            }
                        }
Exemplo n.º 4
0
        /// <summary>
        /// Funzione invocata dall'evento KeyPressed.
        /// Cattura e registra i modificatori premuti ed invia i tasti premuti.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ClientKeyPressed(object sender, KeyEventArgs e)
        {
            Key key;

            if (e.Key == Key.System)
            {
                key = e.SystemKey;
            }
            else
            {
                key = e.Key;
            }

            switch (key)
            {
            case Key.LeftShift:
            case Key.RightShift:
                modifier   = modifier | mod_code.shift;
                Shift.Fill = new SolidColorBrush(Colors.Blue);
                e.Handled  = true;
                break;

            case Key.LeftCtrl:
            case Key.RightCtrl:
                modifier  = modifier | mod_code.ctrl;
                Ctrl.Fill = new SolidColorBrush(Colors.Blue);
                e.Handled = true;
                break;

            case Key.LeftAlt:
            case Key.RightAlt:
                modifier  = modifier | mod_code.alt;
                Alt.Fill  = new SolidColorBrush(Colors.Blue);
                e.Handled = true;
                break;

            default:
                break;
            } // Switch closing bracket

            // Nel caso in cui il tasto premuto non sia un modificatore
            if (e.Handled == false)
            {
                // Preparazione dei dati da inviare
                int    conv_key = KeyInterop.VirtualKeyFromKey(key);
                byte[] buffer   = new byte[1 + sizeof(int)];        // Struttura che conterrà (Modificatori + tasto)
                buffer[0] = (byte)modifier;
                BitConverter.GetBytes(IPAddress.HostToNetworkOrder(conv_key)).CopyTo(buffer, 1);

                // Recupero l'applicazione che è in focus dall'elemento selezionato nella combobox

                ForegroundApp appinfocus = ForegroundAppsBox.SelectedItem as ForegroundApp;
                if (appinfocus == null)
                {
                    e.Handled = true;
                    return;
                }

                // Se c'è almeno un app in focus, cerchiamo il tab o server a cui appartiene
                foreach (DynamicTabItem tab in ServerTabs)
                {
                    if (tab.ForegroundApp == appinfocus.Name)
                    {
                        ServerTabManagement s = tab.Content as ServerTabManagement;
                        if (s != null)
                        {
                            try
                            {
                                s.Stream.BeginWrite(buffer, 0, 1 + sizeof(int), new AsyncCallback(SendToServer), s);
                            }
                            catch (IOException)
                            {
                                ExceptionHandler.SendError(s);
                            }
                        }
                    }
                }

                e.Handled = true;
            }
        } // ClientKeyPressed closing bracket