Пример #1
0
        private Key(SerializationInfo info, StreamingContext context)
        {
            KeyDownStrokes = new List<KeyStroke>();
            KeyUpStrokes = new List<KeyStroke>();

            //int version = info.GetInt32("Version");

            Name = info.GetString("keyName");

            InfoWindowsKeys = info.GetString("InfoWindowsKeys");

            int totalKeyDown = info.GetInt32("TotalKeyDown");
            for (int i = 0; i < totalKeyDown; i++)
            {
                var ks = new KeyStroke();
                ks.code = info.GetUInt16("kd_c_" + i);
                ks.information = info.GetUInt32("kd_i_" + i);
                ks.state = (Keyboard.States)info.GetUInt16("kd_s_" + i);

                KeyDownStrokes.Add(ks);
            }

            int totalKeyUp = info.GetInt32("TotalKeyUp");
            for (int i = 0; i < totalKeyUp; i++)
            {
                var ks = new KeyStroke();
                ks.code = info.GetUInt16("ku_c_" + i);
                ks.information = info.GetUInt32("ku_i_" + i);
                ks.state = (Keyboard.States)info.GetUInt16("ku_s_" + i);

                KeyUpStrokes.Add(ks);
            }

        }
Пример #2
0
        public KeyStroke Clone()
        {
            var newKey = new KeyStroke()
                             {
                                 code = this.code,
                                 information = this.information,
                                 state = this.state
                             };

            return newKey;
        }
Пример #3
0
// ReSharper restore InconsistentNaming

        public KeyStroke Read()
        {
            KEYBOARD_INPUT_DATA outBuffer = new KEYBOARD_INPUT_DATA();
            uint bytesReturned = 0;
            uint outBufferSize = (uint) Marshal.SizeOf(typeof(KEYBOARD_INPUT_DATA));
            RawRead(base.device, 0x222100, IntPtr.Zero, 0, out outBuffer, outBufferSize, out bytesReturned, IntPtr.Zero);
            if (bytesReturned > 0)
            {
                var keyStroke = new KeyStroke();
                keyStroke.code = outBuffer.MakeCode;
                keyStroke.state = (States) outBuffer.Flags;
                keyStroke.information = outBuffer.ExtraInformation;
                return keyStroke;
            }
            return null;
        }
Пример #4
0
 public uint Read(KeyStroke[] keyStrokes, int number)
 {
     if ((number <= 0) || (keyStrokes.Length < number))
     {
         return 0;
     }
     KEYBOARD_INPUT_DATA[] outBuffer = new KEYBOARD_INPUT_DATA[number];
     uint bytesReturned = 0;
     uint num2 = (uint) Marshal.SizeOf(typeof(KEYBOARD_INPUT_DATA));
     RawRead(base.device, 0x222100, IntPtr.Zero, 0, outBuffer, (uint) (number * num2), out bytesReturned, IntPtr.Zero);
     bytesReturned /= num2;
     for (int i = 0; i < bytesReturned; i++)
     {
         keyStrokes[i].code = outBuffer[i].MakeCode;
         keyStrokes[i].state = (States) outBuffer[i].Flags;
         keyStrokes[i].information = outBuffer[i].ExtraInformation;
     }
     return bytesReturned;
 }
Пример #5
0
 internal SendMakeCommand(KeyStroke keyStroke, KeyboardManager keyboardManager, int keyboardNumber)
 {
     _keyStroke = keyStroke;
     _keyboardManager = keyboardManager;
     _keyboardNumber = keyboardNumber;
 }
Пример #6
0
 public uint Read(KeyStroke[] keyStrokes)
 {
     return Read(keyStrokes, keyStrokes.Length);
 }
Пример #7
0
 public uint Write(KeyStroke[] keyStrokes, int number)
 {
     if ((number <= 0) || (keyStrokes.Length < number))
     {
         return 0;
     }
     KEYBOARD_INPUT_DATA[] inBuffer = new KEYBOARD_INPUT_DATA[number];
     uint bytesReturned = 0;
     uint num2 = (uint) Marshal.SizeOf(typeof(KEYBOARD_INPUT_DATA));
     for (int i = 0; i < number; i++)
     {
         inBuffer[i].UnitId = 0;
         inBuffer[i].MakeCode = keyStrokes[i].code;
         inBuffer[i].Flags = (ushort) keyStrokes[i].state;
         inBuffer[i].Reserved = 0;
         inBuffer[i].ExtraInformation = keyStrokes[i].information;
     }
     RawWrite(base.device, 0x222080, inBuffer, (uint) (number * num2), IntPtr.Zero, 0, out bytesReturned, IntPtr.Zero);
     return (bytesReturned / num2);
 }
Пример #8
0
 public uint Write(KeyStroke[] keyStrokes)
 {
     return this.Write(keyStrokes, keyStrokes.Length);
 }
Пример #9
0
 public bool Write(KeyStroke keyStroke)
 {
     KEYBOARD_INPUT_DATA inBuffer = new KEYBOARD_INPUT_DATA();
     uint bytesReturned = 0;
     uint inBufferSize = (uint) Marshal.SizeOf(typeof(KEYBOARD_INPUT_DATA));
     inBuffer.UnitId = 0;
     inBuffer.MakeCode = keyStroke.code;
     inBuffer.Flags = (ushort) keyStroke.state;
     inBuffer.Reserved = 0;
     inBuffer.ExtraInformation = keyStroke.information;
     RawWrite(base.device, 0x222080, ref inBuffer, inBufferSize, IntPtr.Zero, 0, out bytesReturned, IntPtr.Zero);
     return (bytesReturned > 0);
 }
Пример #10
0
 public bool Equals(KeyStroke other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other.code == code && other.information == information && Equals(other.state, state);
 }
Пример #11
0
        public bool SendKeystroke(KeyStroke keyStroke, int keyboardNumber)
        {
            bool result = keyboards[keyboardNumber].Write(keyStroke);
            Console.WriteLine("Enviei keystroke: {0}, id {1}, OK: {2}", keyStroke.ToString(), keyboardNumber, result);

            return result;
        }
Пример #12
0
        public static BitArray GetConnectedKeyboard()
        {
            var anyActive = false;

            var keyboardsStatus = new BitArray(10, false);

            var km = new KeyboardManager();
            var keyStroke = new KeyStroke();

            km.ListenKeyBoard();
            for (int i = 0; i < keyboardsStatus.Length; i++)
            {
                keyStroke.code = 42;
                keyStroke.state = Keyboard.States.MAKE;

                if (km.SendKeystroke(keyStroke, i))
                {
                    if (!anyActive)
                    {
                        anyActive = true;
                        _firstKeyboardActive = i;
                    }
                    //finish the keystroke
                    keyStroke.state = Keyboard.States.BREAK;
                    km.SendKeystroke(keyStroke, i);

                    keyboardsStatus[i] = true;
                }

            }
            km.StopListenKeyBoard();
            return keyboardsStatus;
        }