예제 #1
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)
     {
     }
 }
예제 #2
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;
 }
        public List <string> ShortcutModifiersToList()
        {
            List <string> Modifiers = new List <string>();

            if (Shift)
            {
                Modifiers.Add(SpecialkeysParser.ToString(Keys.Shift));
            }
            if (Ctrl)
            {
                Modifiers.Add(SpecialkeysParser.ToString(Keys.ControlKey));
            }
            if (Alt)
            {
                Modifiers.Add(SpecialkeysParser.ToString(Keys.Menu));
            }
            if (Win)
            {
                Modifiers.Add(SpecialkeysParser.ToString(Keys.LWin));
            }
            return(Modifiers);
        }
예제 #4
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);
            }
        }