Esempio n. 1
0
    public static void Update()
    {
        // Повторяем цикл, пока есть необработанные нажатия
        while (true)
        {
            DeviceID deviceID = Interception.WaitWithTimeout(context, 0);
            if (deviceID == 0)
            {
                break;
            }

            currentDeviceID = deviceID;

            Interception.Stroke stroke = new Interception.Stroke();

            while (Interception.Receive(context, deviceID, ref stroke, 1) > 0)
            {
                Key key = ToKey(stroke.Key);

                if (showKeys)
                {
                    Console.WriteLine("Key: {0}; Scancode: 0x{1:X2}; State: {2}", key, stroke.Key.Code, stroke.Key.State);
                }

                bool processed;

                KeyList deviceDownedKeys = GetOrCreateKeyList(downedKeys, deviceID);

                if (stroke.Key.State.IsKeyDown())
                {
                    if (!deviceDownedKeys.Contains(key))
                    {
                        deviceDownedKeys.Add(key);
                        processed = OnKeyDown(key, false);
                    }
                    else
                    {
                        processed = OnKeyDown(key, true);
                    }
                }
                else
                {
                    deviceDownedKeys.Remove(key);
                    processed = OnKeyUp(key);
                }

                if (!processed)
                {
                    Interception.Send(context, deviceID, ref stroke, 1);
                }
            }
        }
    }