コード例 #1
0
ファイル: SendInputEx.cs プロジェクト: hmahal/KeePass
        private static void FixEventSeq(List <SiEvent> l)
        {
            // Convert chars to keys
            // Keys kMod = Keys.None;
            for (int i = 0; i < l.Count; ++i)
            {
                SiEvent     si = l[i];
                SiEventType t  = si.Type;

                // if(t == SiEventType.KeyModifier)
                // {
                //	if(!si.Down.HasValue) { Debug.Assert(false); continue; }
                //	if(si.Down.Value)
                //	{
                //		Debug.Assert((kMod & si.KeyModifier) == Keys.None);
                //		kMod |= si.KeyModifier;
                //	}
                //	else
                //	{
                //		Debug.Assert((kMod & si.KeyModifier) == si.KeyModifier);
                //		kMod &= ~si.KeyModifier;
                //	}
                // }
                if (t == SiEventType.Char)
                {
                    // bool bLightConv = (kMod == Keys.None);
                    int iVKey = SiCodes.CharToVKey(si.Char, true);
                    if (iVKey > 0)
                    {
                        si.Type = SiEventType.Key;
                        si.VKey = iVKey;
                    }
                }
            }
        }
コード例 #2
0
ファイル: SendInputEx.cs プロジェクト: hmahal/KeePass
        private static List <SiEvent> ParseSpecial(CharStream cs)
        {
            // Skip leading white space
            while (true)
            {
                char ch = cs.PeekChar();
                if (ch == char.MinValue)
                {
                    Debug.Assert(false); return(null);
                }

                if (!char.IsWhiteSpace(ch))
                {
                    break;
                }
                cs.ReadChar();
            }

            // First char is *always* part of the name (support for "{{}", etc.)
            char chFirst = cs.ReadChar();

            if (chFirst == char.MinValue)
            {
                Debug.Assert(false); return(null);
            }

            int           iPart = 0;
            StringBuilder sbName = new StringBuilder(), sbParams =
                new StringBuilder();

            sbName.Append(chFirst);

            while (true)
            {
                char ch = cs.ReadChar();
                if (ch == char.MinValue)
                {
                    Debug.Assert(false); return(null);
                }
                if (ch == '}')
                {
                    break;
                }

                if (iPart == 0)
                {
                    if (char.IsWhiteSpace(ch))
                    {
                        ++iPart;
                    }
                    else
                    {
                        sbName.Append(ch);
                    }
                }
                else
                {
                    sbParams.Append(ch);
                }
            }

            string strName   = sbName.ToString();
            string strParams = sbParams.ToString().Trim();

            uint?ouParam = null;

            if (strParams.Length > 0)
            {
                uint uParamTry;
                if (uint.TryParse(strParams, out uParamTry))
                {
                    ouParam = uParamTry;
                }
            }

            List <SiEvent> l = new List <SiEvent>();

            if (strName.Equals("DELAY", StrUtil.CaseIgnoreCmp))
            {
                if (!ouParam.HasValue)
                {
                    Debug.Assert(false); return(null);
                }

                SiEvent si = new SiEvent();
                si.Type  = SiEventType.Delay;
                si.Delay = ouParam.Value;

                l.Add(si);
                return(l);
            }
            if (strName.StartsWith("DELAY=", StrUtil.CaseIgnoreCmp))
            {
                SiEvent si = new SiEvent();
                si.Type = SiEventType.SetDefaultDelay;

                string strDelay = strName.Substring(6).Trim();
                uint   uDelay;
                if (uint.TryParse(strDelay, out uDelay))
                {
                    si.Delay = uDelay;
                }
                else
                {
                    Debug.Assert(false); return(null);
                }

                l.Add(si);
                return(l);
            }
            if (strName.Equals("VKEY", StrUtil.CaseIgnoreCmp) ||
                strName.Equals("VKEY-NX", StrUtil.CaseIgnoreCmp) ||
                strName.Equals("VKEY-EX", StrUtil.CaseIgnoreCmp))
            {
                if (!ouParam.HasValue)
                {
                    Debug.Assert(false); return(null);
                }

                SiEvent si = new SiEvent();
                si.Type = SiEventType.Key;
                si.VKey = (int)ouParam.Value;

                if (strName.EndsWith("-NX", StrUtil.CaseIgnoreCmp))
                {
                    si.ExtendedKey = false;
                }
                else if (strName.EndsWith("-EX", StrUtil.CaseIgnoreCmp))
                {
                    si.ExtendedKey = true;
                }

                l.Add(si);
                return(l);
            }
            if (strName.Equals("APPACTIVATE", StrUtil.CaseIgnoreCmp))
            {
                SiEvent si = new SiEvent();
                si.Type = SiEventType.AppActivate;
                si.Text = strParams;

                l.Add(si);
                return(l);
            }
            if (strName.Equals("BEEP", StrUtil.CaseIgnoreCmp))
            {
                SiEvent si = new SiEvent();
                si.Type = SiEventType.Beep;
                si.Text = strParams;

                l.Add(si);
                return(l);
            }

            SiCode siCode = SiCodes.Get(strName);

            SiEvent siTmpl = new SiEvent();

            if (siCode != null)
            {
                siTmpl.Type        = SiEventType.Key;
                siTmpl.VKey        = siCode.VKey;
                siTmpl.ExtendedKey = siCode.ExtKey;
            }
            else if (strName.Length == 1)
            {
                siTmpl.Type = SiEventType.Char;
                siTmpl.Char = strName[0];
            }
            else
            {
                throw new FormatException(KPRes.AutoTypeUnknownPlaceholder +
                                          MessageService.NewLine + @"{" + strName + @"}");
            }

            uint uRepeat = 1;

            if (ouParam.HasValue)
            {
                uRepeat = ouParam.Value;
            }

            for (uint u = 0; u < uRepeat; ++u)
            {
                SiEvent si = new SiEvent();
                si.Type        = siTmpl.Type;
                si.VKey        = siTmpl.VKey;
                si.ExtendedKey = siTmpl.ExtendedKey;
                si.Char        = siTmpl.Char;

                l.Add(si);
            }

            return(l);
        }