LibCECTray updates and fixes
authorNate Burr <nate@jeket.com>
Mon, 7 Jan 2013 17:33:09 +0000 (10:33 -0700)
committerNate Burr <nate@jeket.com>
Mon, 7 Jan 2013 17:33:09 +0000 (10:33 -0700)
Added ability to send modifiers by nesting commands in KeyInput.cs

Made it so that if you click the first column in the WMC grid view. It'll send the command to the open app.

Fixed bug with libcec adding the keyup for button commands and making sure they are still executed.

src/LibCecTray/controller/applications/ApplicationController.cs
src/LibCecTray/controller/applications/KeyInput.cs

index 7d0b23d3dc46fca2dc149f7725117a1b53eb4983..8ff6e079e0dee9fc5ca846453c3d7a04165b1b9d 100644 (file)
@@ -114,7 +114,20 @@ namespace LibCECTray.controller.applications
                                 var item = args.RowIndex < ButtonConfig.Count ? ButtonConfig[args.RowIndex] : null;
                                 if (item == null)
                                   return;
-                                (new CecButtonConfigUI(item)).ShowDialog();
+                                if (args.ColumnIndex >= 0)
+                                {
+                                  (new CecButtonConfigUI(item)).ShowDialog();
+                                }
+                                else
+                                {
+                                  var mappedButton = ButtonConfig[item.Key]; 
+                                  if (mappedButton == null || mappedButton.Value.Empty())
+                                    return;
+
+                                    var controlWindow = FindInstance();
+                                    if (controlWindow != IntPtr.Zero && item.Key.Duration == 0)
+                                      mappedButton.Value.Transmit(controlWindow);
+                                }
                               };
 
       foreach (var item in _buttonConfig)
@@ -235,7 +248,7 @@ namespace LibCECTray.controller.applications
         return false;
 
       var controlWindow = FindInstance();
-      if (controlWindow != IntPtr.Zero && key.Duration == 0)
+      if (controlWindow != IntPtr.Zero && (key.Duration == 0 || key.Duration > 500))
         return mappedButton.Value.Transmit(controlWindow);
 
       return false;
index f37fd104fc919506888c6a4512790498ec86c1c0..1830941704e59d84cbf45d3f2b90d1583b08f7ba 100644 (file)
@@ -176,8 +176,39 @@ namespace LibCECTray.controller.applications
     {
       if (input != null)
       {
-        foreach (var item in input._input)
-          _input.Add(item);
+        bool foundModifier = false;
+        if (KeyCount > 0)
+        {
+          for (int i = _input.Count - 1; i >= 0; i--)
+          {
+
+            if (_input[i].Data.Keyboard.Flags == 0 && (
+               (ushort)WindowsAPI.VirtualKeyCode.VK_SHIFT == _input[i].Data.Keyboard.KeyCode ||
+               (ushort)WindowsAPI.VirtualKeyCode.VK_LSHIFT == _input[i].Data.Keyboard.KeyCode ||
+               (ushort)WindowsAPI.VirtualKeyCode.VK_RSHIFT == _input[i].Data.Keyboard.KeyCode ||
+
+               (ushort)WindowsAPI.VirtualKeyCode.VK_CONTROL == _input[i].Data.Keyboard.KeyCode ||
+               (ushort)WindowsAPI.VirtualKeyCode.VK_LCONTROL == _input[i].Data.Keyboard.KeyCode ||
+               (ushort)WindowsAPI.VirtualKeyCode.VK_RCONTROL == _input[i].Data.Keyboard.KeyCode ||
+
+               (ushort)WindowsAPI.VirtualKeyCode.VK_MENU == _input[i].Data.Keyboard.KeyCode ||
+               (ushort)WindowsAPI.VirtualKeyCode.VK_LMENU == _input[i].Data.Keyboard.KeyCode ||
+               (ushort)WindowsAPI.VirtualKeyCode.VK_RMENU == _input[i].Data.Keyboard.KeyCode
+              ))
+            {
+              foundModifier = true;
+              _input.Insert(i+1, input._input[0]);
+              _input.Insert(i+2, input._input[1]);
+              break;
+            }
+          }
+        }
+
+        if (!foundModifier)
+        {
+          _input.Add(input._input[0]);
+          _input.Add(input._input[1]);
+        }
       }
       return this;
     }
@@ -202,12 +233,38 @@ namespace LibCECTray.controller.applications
 
     public ApplicationAction RemoveItem(int index)
     {
-      //both keyup and keydown
-      if (index * 2 + 1 < _input.Count)
+      var current = 0;
+      var downKeyIndex = 0;
+      var upKeyIndex = 0;
+      bool downFound = false;
+
+      for (int i = 0; i < _input.Count; i++)
       {
-        _input.RemoveAt(index * 2);
-        _input.RemoveAt(index * 2);
+        if (_input[i].Data.Keyboard.Flags == 0 && !downFound)
+        {
+          if (index == current)
+          {
+            downKeyIndex = i;
+            downFound = true;
+          }
+          current++;
+        }
+        else if(_input[i].Data.Keyboard.Flags != 0 && downFound)
+        {
+          if (_input[i].Data.Keyboard.KeyCode == _input[downKeyIndex].Data.Keyboard.KeyCode)
+          {
+            upKeyIndex = i;
+            break;
+          }
+        }
       }
+
+      WindowsAPI.Input downKey = _input[downKeyIndex];
+      WindowsAPI.Input upKey = _input[upKeyIndex];
+
+      _input.Remove(downKey);
+      _input.Remove(upKey);
+
       return this;
     }
 
@@ -221,7 +278,7 @@ namespace LibCECTray.controller.applications
         {
           var tmp = string.Format(KeyCount > 1 ? "[{0}] " : "{0} ",
                                   WindowsAPI.GetVirtualKeyName((WindowsAPI.VirtualKeyCode) input.Data.Keyboard.KeyCode));
-          current += tmp.Length + 1;
+          current += tmp.Length;
           if (index <= current)
             return RemoveItem(item);
           item++;