Exemple #1
0
        public void HomeKeyPress()
        {
            UInt32 keyChar = 0x0000FF50;

            vnc.WriteKeyboardEvent(keyChar, true);
            //e.Handled = true;

            //KeyEventArgs e = new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, Key.Home);
            //e.RoutedEvent = UIElement.KeyDownEvent;
            //System.Windows.Input.InputManager.Current.ProcessInput(e);

            //base.OnKeyDown(e);
            //base.OnKeyUp(e);
        }
        // Thanks to Lionel Cuir, Christian and the other developers at
        // Aulofee.com for cleaning-up my keyboard code, specifically:
        // ManageKeyDownAndKeyUp, OnKeyPress, OnKeyUp, OnKeyDown.
        private void ManageKeyDownAndKeyUp(KeyEventArgs e, bool isDown)
        {
            UInt32 keyChar;
            bool   isProcessed = true;

            switch (e.KeyCode)
            {
            case Keys.Tab:                              keyChar = 0x0000FF09;           break;

            case Keys.Enter:                    keyChar = 0x0000FF0D;           break;

            case Keys.Escape:                   keyChar = 0x0000FF1B;           break;

            case Keys.Home:                             keyChar = 0x0000FF50;           break;

            case Keys.Left:                             keyChar = 0x0000FF51;           break;

            case Keys.Up:                               keyChar = 0x0000FF52;           break;

            case Keys.Right:                    keyChar = 0x0000FF53;           break;

            case Keys.Down:                             keyChar = 0x0000FF54;           break;

            case Keys.PageUp:                   keyChar = 0x0000FF55;           break;

            case Keys.PageDown:                 keyChar = 0x0000FF56;           break;

            case Keys.End:                              keyChar = 0x0000FF57;           break;

            case Keys.Insert:                   keyChar = 0x0000FF63;           break;

            case Keys.ShiftKey:                 keyChar = 0x0000FFE1;           break;

            // BUG FIX -- added proper Alt/CTRL support (Edward Cooke)
            case Keys.Alt:              keyChar = 0x0000FFE9;       break;

            case Keys.ControlKey:       keyChar = 0x0000FFE3;       break;

            case Keys.LControlKey:      keyChar = 0x0000FFE3;       break;

            case Keys.RControlKey:      keyChar = 0x0000FFE4;       break;

            case Keys.Menu:                             keyChar = 0x0000FFE9;           break;

            case Keys.Delete:                   keyChar = 0x0000FFFF;           break;

            case Keys.LWin:                             keyChar = 0x0000FFEB;           break;

            case Keys.RWin:                             keyChar = 0x0000FFEC;           break;

            case Keys.Apps:                             keyChar = 0x0000FFEE;           break;

            case Keys.F1:
            case Keys.F2:
            case Keys.F3:
            case Keys.F4:
            case Keys.F5:
            case Keys.F6:
            case Keys.F7:
            case Keys.F8:
            case Keys.F9:
            case Keys.F10:
            case Keys.F11:
            case Keys.F12:
                keyChar = 0x0000FFBE + ((UInt32)e.KeyCode - (UInt32)Keys.F1);
                break;

            default:
                keyChar     = 0;
                isProcessed = false;
                break;
            }

            if (isProcessed)
            {
                vnc.WriteKeyboardEvent(keyChar, isDown);
                e.Handled = true;
            }
        }
Exemple #3
0
        protected void SyncModifierKeyState(KeyboardHook.ModifierKeys modifierKeys)
        {
            if ((PreviousModifierKeyState & KeyboardHook.ModifierKeys.LeftShift) !=
                (modifierKeys & KeyboardHook.ModifierKeys.LeftShift))
            {
                vnc.WriteKeyboardEvent(RfbProtocol.XK_Shift_L, (modifierKeys & KeyboardHook.ModifierKeys.LeftShift) != 0);
            }
            if ((PreviousModifierKeyState & KeyboardHook.ModifierKeys.RightShift) !=
                (modifierKeys & KeyboardHook.ModifierKeys.RightShift))
            {
                vnc.WriteKeyboardEvent(RfbProtocol.XK_Shift_R, (modifierKeys & KeyboardHook.ModifierKeys.RightShift) != 0);
            }

            if ((PreviousModifierKeyState & KeyboardHook.ModifierKeys.LeftControl) !=
                (modifierKeys & KeyboardHook.ModifierKeys.LeftControl))
            {
                vnc.WriteKeyboardEvent(RfbProtocol.XK_Control_L, (modifierKeys & KeyboardHook.ModifierKeys.LeftControl) != 0);
            }
            if ((PreviousModifierKeyState & KeyboardHook.ModifierKeys.RightControl) !=
                (modifierKeys & KeyboardHook.ModifierKeys.RightControl))
            {
                vnc.WriteKeyboardEvent(RfbProtocol.XK_Control_R, (modifierKeys & KeyboardHook.ModifierKeys.RightControl) != 0);
            }

            if ((PreviousModifierKeyState & KeyboardHook.ModifierKeys.LeftAlt) !=
                (modifierKeys & KeyboardHook.ModifierKeys.LeftAlt))
            {
                vnc.WriteKeyboardEvent(RfbProtocol.XK_Alt_L, (modifierKeys & KeyboardHook.ModifierKeys.LeftAlt) != 0);
            }
            if ((PreviousModifierKeyState & KeyboardHook.ModifierKeys.RightAlt) !=
                (modifierKeys & KeyboardHook.ModifierKeys.RightAlt))
            {
                vnc.WriteKeyboardEvent(RfbProtocol.XK_Alt_R, (modifierKeys & KeyboardHook.ModifierKeys.RightAlt) != 0);
            }

            if ((PreviousModifierKeyState & KeyboardHook.ModifierKeys.LeftWin) !=
                (modifierKeys & KeyboardHook.ModifierKeys.LeftWin))
            {
                vnc.WriteKeyboardEvent(RfbProtocol.XK_Super_L, (modifierKeys & KeyboardHook.ModifierKeys.LeftWin) != 0);
            }
            if ((PreviousModifierKeyState & KeyboardHook.ModifierKeys.RightWin) !=
                (modifierKeys & KeyboardHook.ModifierKeys.RightWin))
            {
                vnc.WriteKeyboardEvent(RfbProtocol.XK_Super_R, (modifierKeys & KeyboardHook.ModifierKeys.RightWin) != 0);
            }

            PreviousModifierKeyState = modifierKeys;
        }