Esempio n. 1
0
 protected override void WndProc(ref Message m)
 {
     if (m.Msg == 0xFF)
     {
         KeyboardRawInput.RawKeyboard keyboard = new KeyboardRawInput.RawKeyboard();
         uint size   = (uint)Marshal.SizeOf(keyboard);
         uint result = KeyboardRawInput.GetRawInputData(m.LParam, 0x10000003, ref keyboard, ref size, 4 + 4 + IntPtr.Size * 2);
         if (result != uint.MaxValue)
         {
             string parse = string.Format("MakeCode: 0x{0:X}\r\nMessage: 0x{1:X}\r\nVKey: 0x{2:X}", keyboard.MakeCode, keyboard.Message, keyboard.VKey);
             MessageBox.Show(parse);
         }
     }
     base.WndProc(ref m);
 }
Esempio n. 2
0
        protected override void OnLoad(EventArgs e)
        {
            try {
                KeyboardRawInput.RawInputDevice dev = new KeyboardRawInput.RawInputDevice();
                dev.Page  = 1;
                dev.Usage = 6;
                dev.Flags = 0x00000100 /*RIDEV_INPUTSINK*/;
                dev.HWnd  = this.Handle;
                bool result = KeyboardRawInput.RegisterRawInputDevices(new KeyboardRawInput.RawInputDevice[] { dev }, 1, Marshal.SizeOf(typeof(KeyboardRawInput.RawInputDevice)));
                if (!result)
                {
                    throw new Exception(string.Format("LastError: 0x{0:x}", Marshal.GetLastWin32Error()));
                }
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Error registering RawInput");
            }

            base.OnLoad(e);
        }