From: Nate Burr Date: Mon, 7 Jan 2013 17:33:09 +0000 (-0700) Subject: LibCECTray updates and fixes X-Git-Tag: upstream/2.2.0~1^2~6^2~20^2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=92e1fc9c5016229678c2b8d00360603fd8f791c8;p=deb_libcec.git LibCECTray updates and fixes 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. --- diff --git a/src/LibCecTray/controller/applications/ApplicationController.cs b/src/LibCecTray/controller/applications/ApplicationController.cs index 7d0b23d..8ff6e07 100644 --- a/src/LibCecTray/controller/applications/ApplicationController.cs +++ b/src/LibCecTray/controller/applications/ApplicationController.cs @@ -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; diff --git a/src/LibCecTray/controller/applications/KeyInput.cs b/src/LibCecTray/controller/applications/KeyInput.cs index f37fd10..1830941 100644 --- a/src/LibCecTray/controller/applications/KeyInput.cs +++ b/src/LibCecTray/controller/applications/KeyInput.cs @@ -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++;