X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FLibCecTray%2Fcontroller%2Fapplications%2FKeyInput.cs;h=76e861b76e8762c526f19bba71fd2493415f9833;hb=2a80b46be78e9d849de223ab73b6f3e7b4d9fc46;hp=f37fd104fc919506888c6a4512790498ec86c1c0;hpb=90b7066f7129c01c5bd012a00677ebdc0c42ae89;p=deb_libcec.git diff --git a/src/LibCecTray/controller/applications/KeyInput.cs b/src/LibCecTray/controller/applications/KeyInput.cs index f37fd10..76e861b 100644 --- a/src/LibCecTray/controller/applications/KeyInput.cs +++ b/src/LibCecTray/controller/applications/KeyInput.cs @@ -1,7 +1,7 @@ /* * This file is part of the libCEC(R) library. * - * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved. + * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved. * libCEC(R) is an original work, containing original code. * * libCEC(R) is a trademark of Pulse-Eight Limited. @@ -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++; @@ -233,4 +290,4 @@ namespace LibCECTray.controller.applications private readonly List _input = new List(); } -} \ No newline at end of file +}