Ejemplo n.º 1
0
 public void EnumerateKeyboards()
 {
     lock (_lock)
     {
         _keyboardList.Clear();
         var rawKeyboardDevice = new RawKeyboardDevice("Global Keyboard", RawDeviceType.Keyboard, IntPtr.Zero, "Fake Keyboard. Some keys (ZOOM, MUTE, VOLUMEUP, VOLUMEDOWN) are sent to rawinput with a handle of zero.");
         _keyboardList.Add(rawKeyboardDevice.Handle, rawKeyboardDevice);
         uint devices = 0u;
         int  size    = Marshal.SizeOf(typeof(RawInputDeviceList));
         if (Win32Methods.GetRawInputDeviceList(IntPtr.Zero, ref devices, (uint)size) != 0u)
         {
             throw new Win32Exception(Marshal.GetLastWin32Error());
         }
         IntPtr pRawInputDeviceList = Marshal.AllocHGlobal((int)(size * devices));
         try
         {
             Win32Methods.GetRawInputDeviceList(pRawInputDeviceList, ref devices, (uint)size);
             int index = 0;
             while (index < devices)
             {
                 RawKeyboardDevice device = GetKeyboard(pRawInputDeviceList, size, index);
                 if (device != null && !_keyboardList.ContainsKey(device.Handle))
                 {
                     _keyboardList.Add(device.Handle, device);
                 }
                 index++;
             }
         }
         finally
         {
             Marshal.FreeHGlobal(pRawInputDeviceList);
         }
         NumberOfKeyboards = _keyboardList.Count;
     }
 }
Ejemplo n.º 2
0
 internal RawInputKeyboardEventArgs(RawKeyboardDevice device, KeyPressState keyPressState, uint message, Key key, int virtualKey)
 {
     Device        = device;
     KeyPressState = keyPressState;
     Message       = message;
     Key           = key;
     VirtualKey    = virtualKey;
 }