Esempio n. 1
0
 static Script()
 {
     context = Interception.CreateContext();
     Interception.SetFilter(context, Interception.IsKeyboard, Interception.Filter.All);
 }
Esempio n. 2
0
        public static void Run()
        {
            var input = new List <Interception.KeyStroke>(6);

            var stroke  = new Interception.Stroke();
            var context = Interception.CreateContext();

            Interception.SetFilter(context, Interception.IsKeyboard, Interception.Filter.All);

            try
            {
                while (true)
                {
                    var device = Interception.Wait(context);
                    if (Interception.Receive(context, device, ref stroke, 1) <= 0)
                    {
                        break;
                    }

                    if (device == 1)
                    {
                        input.Add(stroke.key);

                        while (input.Count > 0)
                        {
                            var match = FindMatch(input);
                            if (match == null)
                            {
                                stroke.key = input[0];
                                Interception.Send(context, 1, ref stroke, 1);
                                input.RemoveAt(0);
                                continue;
                            }
                            else
                            {
                                if (match.Length > 0)
                                {
                                    for (var i = 0; i < match.Length; i++)
                                    {
                                        stroke.key = match[i];
                                        Interception.Send(context, 1, ref stroke, 1);
                                    }
                                    input.Clear();
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        var key = stroke.key;

                        for (var i = 0; i < input.Count; i++)
                        {
                            stroke.key = input[i];
                            Interception.Send(context, 1, ref stroke, 1);
                        }
                        input.Clear();

                        stroke.key = key;
                        Interception.Send(context, device, ref stroke, 1);
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                Interception.DestroyContext(context);
            }
        }