Esempio n. 1
0
 private void OnKeystrokeEvent(KeystrokeEventArgs e)
 {
     if (KeystrokeEvent != null)
     {
         KeystrokeEvent(e);
     }
 }
Esempio n. 2
0
        private void RemoveModifier(Keys keys, KeystrokeEventArgs e)
        {
            // If Left Shift is released, then only unset Shift if RShift is not set
            switch (keys)
            {
            case Keys.ControlKey: e.Ctrl = false; break;

            case Keys.LControlKey: e.LCtrl = false; e.Ctrl = e.RCtrl; break;

            case Keys.RControlKey: e.RCtrl = false; e.Ctrl = e.LCtrl; break;

            case Keys.ShiftKey: e.Shift = false; break;

            case Keys.LShiftKey: e.LShift = false; e.Shift = e.RShift; break;

            case Keys.RShiftKey: e.RShift = false; e.Shift = e.LShift; break;

            case Keys.LWin: e.LWin = false; break;

            case Keys.RWin: e.RWin = false; break;

            case Keys.Menu: e.Alt = false; break;

            case Keys.LMenu: e.LAlt = false; e.Alt = e.RAlt; break;

            case Keys.RMenu: e.RAlt = false; e.Alt = e.LAlt; break;

            case Keys.NumLock: e.Numlock = false; break;

            case Keys.Scroll: e.Scrollock = false; break;

            case Keys.CapsLock: e.Caps = false; break;
            }
        }
Esempio n. 3
0
        private void AddModifier(Keys keys, KeystrokeEventArgs e)
        {
            switch (keys)
            {
            case Keys.ControlKey: e.Ctrl = true; break;

            case Keys.LControlKey: e.LCtrl = true; e.Ctrl = true; break;

            case Keys.RControlKey: e.RCtrl = true; e.Ctrl = true; break;

            case Keys.ShiftKey: e.Shift = true; break;

            case Keys.LShiftKey: e.LShift = true; e.Shift = true; break;

            case Keys.RShiftKey: e.RShift = true; e.Shift = true; break;

            case Keys.LWin: e.LWin = true; break;

            case Keys.RWin: e.RWin = true; break;

            case Keys.Menu: e.Alt = true; break;

            case Keys.LMenu: e.LAlt = true; e.Alt = true; break;

            case Keys.RMenu: e.RAlt = true; e.Alt = true; break;

            case Keys.NumLock: e.Numlock = true; break;

            case Keys.Scroll: e.Scrollock = true; break;

            case Keys.CapsLock: e.Caps = true; break;
            }
        }
Esempio n. 4
0
 private void BackupDeadKey(KeystrokeEventArgs e)
 {
     if (e.KeyString == "DEADKEY")
     {
         e.KeyString      = "!";
         lastDeadKeyEvent = e;
     }
 }
        void k_KeystrokeEvent(KeystrokeEventArgs e)
        {
            CheckForSettingsMode(e);
            if (e.ShouldBeDisplayed)
            {
                if (settings.EnableWindowFade && Opacity < 1)
                {
                    FadeIn();
                }

                if (!e.RequiresNewLine &&
                    NumberOfDeletionsAllowed > 0 &&
                    LastHistoryLineIsText &&
                    !LastHistoryLineRequiredNewLineAfterwards &&
                    e.NoModifiers &&
                    e.Key == Keys.Back)
                {
                    Log.e("BS", "delete last char");
                    Log.e("BS", "NumberOfDeletionsAllowed " + NumberOfDeletionsAllowed.ToString());
                    if (!removeLastChar())
                    {
                        // again
                        Log.e("BS", " failed");
                        NumberOfDeletionsAllowed = 0;
                        k_KeystrokeEvent(e);
                        return;
                    }
                }
                else if (e.RequiresNewLine ||
                         !addingWouldFitInCurrentLine(e.ToString(false)) ||
                         !LastHistoryLineIsText ||
                         LastHistoryLineRequiredNewLineAfterwards)
                {
                    addNextLine(e.ToString(false));
                    NumberOfDeletionsAllowed = e.Deletable ? 1 : 0;
                    Log.e("BS", "NumberOfDeletionsAllowed " + NumberOfDeletionsAllowed.ToString());
                }
                else
                {
                    Log.e("BS", "add to line ");
                    addToLine(e.ToString(false));
                    if (e.Deletable)
                    {
                        NumberOfDeletionsAllowed += 1;
                    }
                    else
                    {
                        NumberOfDeletionsAllowed = 0;
                    }
                    Log.e("BS", "NumberOfDeletionsAllowed " + NumberOfDeletionsAllowed.ToString());
                }

                LastHistoryLineIsText = e.StrokeType == KeystrokeType.Text;
                LastHistoryLineRequiredNewLineAfterwards = e.RequiresNewLineAfterwards;
            }
        }
Esempio n. 6
0
 private void CheckForSettingsMode(KeystrokeEventArgs e)
 {
     if (e.Ctrl && e.Shift && e.Alt)
     {
         ActivateSettingsMode();
     }
     else
     {
         ActivateDisplayOnlyMode(false);
     }
 }
Esempio n. 7
0
 private string ParseNumeric(KeystrokeEventArgs e)
 {
     if (e.IsNumericFromNumbers)
     {
         return((e.vkCode - (int)Keys.D0).ToString());
     }
     else if (e.IsNumericFromNumpad)
     {
         return((e.vkCode - (int)Keys.NumPad0).ToString());
     }
     return("BUG1");
 }
Esempio n. 8
0
 private void ParseTexttViaSpecialkeysParser(KeystrokeEventArgs e)
 {
     try
     {
         e.KeyString                 = SpecialkeysParser.ToString(e.Key);
         e.ShouldBeDisplayed         = true;
         e.StrokeType                = KeystrokeType.Text;
         e.RequiresNewLineAfterwards = (Keys)e.vkCode == Keys.Return;
     }
     catch (NotImplementedException)
     {
     }
 }
Esempio n. 9
0
 private void ParseShortcutViaSpecialkeysParser(KeystrokeEventArgs e)
 {
     try
     {
         e.KeyString = SpecialkeysParser.ToString(e.Key);
     }
     catch (NotImplementedException)
     {
         e.KeyString = e.Key.ToString();
     }
     e.ShouldBeDisplayed         = true;
     e.StrokeType                = KeystrokeType.Shortcut;
     e.RequiresNewLine           = true;
     e.RequiresNewLineAfterwards = true;
 }
Esempio n. 10
0
        private string ParseChar(KeystrokeEventArgs e)
        {
            string c = ((Keys)e.vkCode).ToString();

            if (!e.Uppercase)
            {
                c = c.ToLower();
            }

            // We parse the Shift and Caps keys into the Upper/Lowercase
            e.Shift  = false;
            e.Caps   = false;
            e.LShift = false;
            e.RShift = false;
            return(c);
        }
Esempio n. 11
0
 private bool ApplyDeadKey(KeystrokeEventArgs e)
 {
     if (lastDeadKeyEvent != null)
     {
         lastDeadKeyEvent.KeyString = KeyboardLayoutParser.ProcessDeadkeyWithNextKey(lastDeadKeyEvent, e);
         if (lastDeadKeyEvent.KeyString == "")
         {
             lastDeadKeyEvent = null;
             return(false);
         }
         OnKeystrokeEvent(lastDeadKeyEvent);
         lastDeadKeyEvent = null;
         return(true);
     }
     return(false);
 }
Esempio n. 12
0
        /// <summary>
        /// Gets a KeyboardRawKeyEvent, parses it and forwards it via
        /// the KeystrokeEvent
        /// </summary>
        /// <param name="e"></param>
        void hook_KeyEvent(KeyboardRawEventArgs raw_e)
        {
            KeystrokeEventArgs e = new KeystrokeEventArgs(raw_e);

            e.IsAlpha              = CheckIsAlpha(e);
            e.IsNumericFromNumpad  = CheckIsNumericFromNumpad(e);
            e.IsNumericFromNumbers = CheckIsNumericFromNumbers(e);
            e.IsNoUnicodekey       = CheckIsNoUnicodekey(e);
            e.IsFunctionKey        = CheckIsFunctionKey(e);
            e.ModifierToggledEvent = CheckVkCodeIsModifier(e);

            Log.e("KP", "   alpha:" + e.IsAlpha.ToString());

            if (e.Method == KeyUpDown.Down)
            {
                ApplyDeadKey(e);
                if (e.IsAlpha && e.OnlyShiftOrCaps)
                {
                    e.KeyString         = ParseChar(e);
                    e.ShouldBeDisplayed = true;
                    e.StrokeType        = KeystrokeType.Text;
                    e.Deletable         = true;
                    Log.e("KP", "   IsAlpha and OnlyShiftOrCaps > ParseChar");
                }
                else if (e.IsNumeric && e.NoModifiers)
                {
                    e.KeyString         = ParseNumeric(e);
                    e.ShouldBeDisplayed = true;
                    e.StrokeType        = KeystrokeType.Text;
                    e.Deletable         = true;
                    Log.e("KP", "   e.IsNumeric && e.NoModifiers > ParseNumeric");
                }
                else if (e.ModifierToggledEvent) // vkcode is modifier
                {
                    e.ShouldBeDisplayed = false;
                    AddModifier((Keys)e.vkCode, e);
                    e.StrokeType = KeystrokeType.Modifiers;
                    Log.e("KP", "   e.ModifierToggledEvent > AddModifier " + ((Keys)e.vkCode).ToString());
                }
                else if (e.IsNoUnicodekey && e.NoModifiers)
                {
                    ParseTexttViaSpecialkeysParser(e);
                    e.Deletable = IsDeletableSpecialKey(e.Key);
                    Log.e("KP", "   e.IsNoUnicodekey && e.NoModifiers > ParseTexttViaSpecialkeysParser ");
                }
                else if (e.IsNoUnicodekey && !e.NoModifiers) // Shortcut
                {
                    ParseShortcutViaSpecialkeysParser(e);
                    Log.e("KP", "   e.IsNoUnicodekey && !e.NoModifiers > ParseShortcutViaSpecialkeysParser ");
                }
                else if (e.NoModifiers) // Simple Key, but not alphanumeric (first try special then unicode)
                {
                    Log.e("KP", "   e.NoModifiers > try SpecialkeysParser.ToString ");
                    try
                    {
                        e.KeyString = SpecialkeysParser.ToString((Keys)e.vkCode);
                    }
                    catch (NotImplementedException)
                    {
                        Log.e("KP", "   e.NoModifiers 2> try KeyboardLayoutParser.ParseViaToUnicode ");
                        e.KeyString = KeyboardLayoutParser.ParseViaToUnicode(e);
                        BackupDeadKey(e);
                    }
                    e.ShouldBeDisplayed         = true;
                    e.StrokeType                = KeystrokeType.Text;
                    e.RequiresNewLineAfterwards = (Keys)e.vkCode == Keys.Return;
                }
                else if (e.OnlyShiftOrCaps) //  special char, but only Shifted, eg ;:_ÖÄ'*ÜP
                // (e.IsNoUnicodekey is always false here -> could be a unicode key combinatin)
                {
                    e.KeyString = KeyboardLayoutParser.ParseViaToUnicode(e);
                    BackupDeadKey(e);
                    Log.e("KP", "   e.OnlyShiftOrCaps > try KeyboardLayoutParser.ParseViaToUnicode ");

                    if (e.KeyString != "")
                    {
                        e.ShouldBeDisplayed = true;
                        e.StrokeType        = KeystrokeType.Text;
                        e.Deletable         = true;
                    }
                    else
                    {
                        // Is no unicode key combination? maybe a shortcut then: Shift + F2
                        ParseShortcutViaSpecialkeysParser(e);
                        Log.e("KP", "   e.OnlyShiftOrCaps 2> ParseShortcutViaSpecialkeysParser ");
                    }
                }
                else if (!e.NoModifiers && !e.OnlyShiftOrCaps) // Special Char with Strg + Alt
                // or shortcut else
                {
                    // could be something like the german @ (Ctrl + Alt + Q)
                    // Temporary disabled because ToUnicode returns more often values than it should
                    e.KeyString = ""; //KeyboardLayoutParser.ParseViaToUnicode(e);
                    Log.e("KP", "   !e.NoModifiers && !e.OnlyShiftOrCapss > KeyboardLayoutParser.ParseViaToUnicode");
                    // all other special char keycodes do not use Shift
                    if (e.KeyString != "" && !e.Shift && !e.IsNoUnicodekey)
                    {
                        e.ShouldBeDisplayed = true;
                        e.StrokeType        = KeystrokeType.Text;
                        e.Deletable         = true;
                    }
                    else // Shortcut
                    {
                        ParseShortcutViaSpecialkeysParser(e);
                        string possibleChar = KeyboardLayoutParser.ParseViaToUnicode(e);
                        BackupDeadKey(e);
                        if (possibleChar != "" && !CheckIsAlpha(possibleChar) &&
                            !CheckIsNumeric(possibleChar) &&
                            CheckIsASCII(possibleChar))
                        {
                            e.KeyString += " (" + possibleChar + ")";
                        }
                        Log.e("KP", "   !e.NoModifiers && !e.OnlyShiftOrCapss 2> ParseShortcutViaSpecialkeysParser ");
                    }
                }
                Log.e("KP", "   str:" + e.KeyString);
            }

            if (e.Method == KeyUpDown.Up)
            {
                if (e.ModifierToggledEvent) // vkcode is modifier
                {
                    e.ShouldBeDisplayed = false;
                    RemoveModifier((Keys)e.vkCode, e);
                    e.StrokeType = KeystrokeType.Modifiers;
                }
                Log.e("KP", "   code:" + ((Keys)e.vkCode).ToString());

                // only react to modifiers on key up, nothing else
            }

            if (e.StrokeType != KeystrokeType.Undefined)
            {
                OnKeystrokeEvent(e);
            }
        }