Exemplo n.º 1
0
        public static bool GetRawInputData(IntPtr hRawInput,
                                           ref RAWINPUTHEADER header,
                                           ref RAWMOUSE mouse,
                                           ref RAWKEYBOARD keyboard,
                                           ref RAWHID hid)
        {
            int iSize = 0;

            GetRawInputData(hRawInput, 0x10000003, IntPtr.Zero, ref iSize, Marshal.SizeOf <RAWINPUTHEADER>()); // RID_INPUT
            if (iSize == 0)
            {
                return(false);
            }

            IntPtr mem = Marshal.AllocHGlobal(iSize);

            if (mem == IntPtr.Zero)
            {
                return(false);
            }

            if (GetRawInputData(hRawInput, 0x10000003, mem, ref iSize, Marshal.SizeOf <RAWINPUTHEADER>()) != iSize)
            {
                Marshal.FreeHGlobal(mem);
                return(false);
            }

            if (Environment.Is64BitProcess)
            {
                var str = Marshal.PtrToStructure <RAWINPUT64>(mem);
                header   = str.header;
                mouse    = str.mouse;
                keyboard = str.keyboard;
                hid      = str.hid;
            }
            else
            {
                var str = Marshal.PtrToStructure <RAWINPUT32>(mem);
                header   = str.header;
                mouse    = str.mouse;
                keyboard = str.keyboard;
                hid      = str.hid;
            }

            Marshal.FreeHGlobal(mem);
            return(true);
        }
Exemplo n.º 2
0
        public void InputFromKeyboard_Heatmap(RAWINPUTHEADER riHeader, RAWKEYBOARD riKeyboard)
        {
            if (riKeyboard.Flags == 0x0)
            {
                return;
            }
            ;
            if (riKeyboard.Flags == 0x2 && Control.IsKeyLocked(Keys.NumLock))
            {
                return;
            }
            ;

            int currentKey = keys.GetKeyCode(riKeyboard.MakeCode, riKeyboard.VKey, riKeyboard.Flags, Control.IsKeyLocked(Keys.NumLock));

            keyMatrix[currentKey].NewStrike();
        }
Exemplo n.º 3
0
 //TODO: keystate and modifier keys.
 private void ProcessRawKeyboardInput(RAWKEYBOARD keyboard, RAWINPUTHEADER rh)
 {
     KeyboardInput?.Invoke(this, new RawKeyboardInputEventArgs(rh, keyboard));
 }
 public RawKeyboardInputEventArgs(RAWINPUTHEADER header, RAWKEYBOARD data)
 {
     Header = header;
     Data   = data;
 }
Exemplo n.º 5
0
        public void InputFromKeyboard_SingleLight(RAWINPUTHEADER riHeader, RAWKEYBOARD riKeyboard)
        {
            if (riKeyboard.Flags == 0x0)
            {
                return;
            }
            ;
            if (riKeyboard.Flags == 0x2 && Control.IsKeyLocked(Keys.NumLock))
            {
                return;
            }
            ;


            string s = "";

            s = s + "0x" + riKeyboard.MakeCode.ToString("X4");
            s = s + "  0x" + riKeyboard.VKey.ToString("X4");
            //            s = s + "  Mssg: 0x" + riKeyboard.Message.ToString("X4");
            s = s + "  0x" + riKeyboard.Flags.ToString("X4");
            //            s = s + "   Rsrvd: 0x" + riKeyboard.Reserved.ToString("X4");
            //            s = s + "   ExInf: 0x" + riKeyboard.ExtraInformation.ToString("X4");
            //            s = s + "  Devc: 0x" + riHeader.hDevice.ToString("X4");
            //            s = s + "   .Size: 0x" + riHeader.dwSize.ToString("X4");
            //            s = s + "   .Type: 0x" + riHeader.dwType.ToString("X4");
            //            s = s + "   wPara: 0x" + riHeader.wParam.ToString("X4");
            System.Diagnostics.Debug.Write(s);
            UpdateStatusMessage.ShowStatusMessage(5, s);


            int currentKey = keys.GetKeyCode(riKeyboard.MakeCode, riKeyboard.VKey, riKeyboard.Flags, Control.IsKeyLocked(Keys.NumLock));
            int sR = 0; int sG = 0; int sB = 0;
            int eR = 0; int eG = 0; int eB = 0;

            switch (Program.ReactTypeStart)
            {
            case 0:
                sR = Program.ReactColors.StartR;
                sG = Program.ReactColors.StartG;
                sB = Program.ReactColors.StartB;
                break;

            case 1:
                //Figure out how to make a rainbow here, probably going to need to rewrite SingleKeyFade classs
                break;

            case 2:
                sR = rnd.Next(Program.ReactColors.SRandRLow, Program.ReactColors.SRandRHigh);
                sG = rnd.Next(Program.ReactColors.SRandGLow, Program.ReactColors.SRandGHigh);
                sB = rnd.Next(Program.ReactColors.SRandBLow, Program.ReactColors.SRandBHigh);
                break;

            default:
                break;
            }

            switch (Program.ReactTypeEnd)
            {
            case 0:
                eR = Program.ReactColors.EndR;
                eG = Program.ReactColors.EndG;
                eB = Program.ReactColors.EndB;
                break;

            case 1:
                if (Program.StaticKeyColors[currentKey] != Color.Transparent)
                {
                    eR = Program.StaticKeyColors[currentKey].R;
                    eG = Program.StaticKeyColors[currentKey].G;
                    eB = Program.StaticKeyColors[currentKey].B;
                }
                break;

            case 2:
                eR = rnd.Next(Program.ReactColors.ERandRLow, Program.ReactColors.ERandRHigh);
                eG = rnd.Next(Program.ReactColors.ERandGLow, Program.ReactColors.ERandGHigh);
                eB = rnd.Next(Program.ReactColors.ERandBLow, Program.ReactColors.ERandBHigh);
                break;

            default:
                break;
            }

            keyMatrix[currentKey] = new SingleKeyFade(
                Program.ReactSettings.Duration,
                (byte)sR,
                (byte)sG,
                (byte)sB,
                (byte)eR,
                (byte)eG,
                (byte)eB);
        }