public VirtualKeyPressedEventArgs(RoutedEvent routedEvent, VKey vkey, Key modifierKey) : base(routedEvent) { _vkey = vkey; _modifierKey = modifierKey; }
private void RefillKeys(string switcherooCode,VKey key = null) { Switcheroo switcheroo = SelectedKeyboard.Switcheroos.FirstOrDefault(x => x.Name == switcherooCode); TextFontFamilyUri = String.IsNullOrEmpty(switcheroo.FontFamilyUri) ? switcheroo.FontFamily : switcheroo.FontFamilyUri; VKeys.Clear(); foreach (VKey k in switcheroo.KeyCollection) { VKeys.Add(k); } if (key == null) return; //this is to ensure that the pressed keys remain the same List<VKey> keys = switcheroo.KeyCollection.FindAll(vkey => key.Value == vkey.Value); foreach (VKey k in keys) { k.IsPressed = key.IsPressed; } //reset the current key state ,since it now belongs to previous key collection... if (!String.IsNullOrEmpty(key.SwitcherooCode)) key.IsPressed = !key.IsPressed; }
private void SetLockStatus(VKey vkey,bool status) { Switcheroo switcheroo = SelectedKeyboard.Switcheroos.FirstOrDefault(x => x.Name == vkey.SwitcherooCode && x.IsVolatile); if (switcheroo != null) { foreach (var key in switcheroo.KeyCollection.Where(k => k.IsPressed)) { key.IsLocked = status; } } }
private void HandleSwitcherooOrPageActionKey(VKey key) { string switcherooCode = key.KeyType == KeyType.Switcheroo ? HandleSwitcherooKey(key) : HandlePageActionKey(key); //update the keys RefillKeys(switcherooCode,key); }
private string HandleSwitcherooKey(VKey key) { string switcherooCode = key.SwitcherooCode; //switch the layout ... switcherooCode = key.IsPressed ? switcherooCode : SelectedKeyboard.DefaultSwitcheroo; //unlock the key if it is locked SetLockStatus(key,false); if (_selectedSwitcheroo == null || _selectedSwitcheroo.Name != switcherooCode) { Switcheroo switcheroo = SelectedKeyboard.Switcheroos.First(s => s.Name == switcherooCode); //we switched the layout so reset the page index _currentPageIndex = 0; //enable the keys with page action next, and disable the previous List<VKey> pageKeys = switcheroo.KeyCollection.FindAll(vkey => null != vkey.PageAction); foreach (VKey item in pageKeys) { item.IsEnabled = item.PageAction == "next"; } _selectedSwitcheroo = switcheroo; } //update the modifier key status return switcherooCode; }
private string HandlePageActionKey(VKey key) { string switcherooCode = key.SwitcherooCode; int maxPages = SelectedKeyboard.Switcheroos.First(x => x.Name == switcherooCode).PageCount; switch (key.PageAction.ToLower()) { case "next": _currentPageIndex++; switcherooCode = switcherooCode + _currentPageIndex; break; case "previous": _currentPageIndex--; switcherooCode = _currentPageIndex == 0 ? switcherooCode : switcherooCode + _currentPageIndex; break; } Switcheroo switcheroo = SelectedKeyboard.Switcheroos.First(s => s.Name == switcherooCode); //update page action keys state List<VKey> pageKeys = switcheroo.KeyCollection.FindAll(vkey => null != vkey.PageAction); foreach (VKey item in pageKeys) { if (item.PageAction == "next") { item.IsEnabled = _currentPageIndex == 0 & maxPages > 1; } else { item.IsEnabled = _currentPageIndex != 0; } } return switcherooCode; }
private bool CanKeyPress(VKey key) { return true; }
private static VKey BuildKeyFromElement(int rowIndex, int colIndex, XElement key, Action<object> keyPress, Func<VKey, bool> canPress) { var vkey = new VKey { UsesRenderer = key.Attribute("usesRenderer") != null && bool.Parse(key.Attribute("usesRenderer").Value), Row = rowIndex, Rotate = key.Attribute("rotate") == null ? 0 : int.Parse(key.Attribute("rotate").Value), RowSpan = key.Attribute("rowspan") == null ? 1 : int.Parse(key.Attribute("rowspan").Value), IsEnabled = key.Attribute("enabled") == null || bool.Parse(key.Attribute("enabled").Value), KeyType = KeyboardUtilities.ParseKeyType(key.Attribute("keytype") == null ? "text" : key.Attribute("keytype").Value), KeyCode = KeyboardUtilities.ParseKeyCode(key.Attribute("keycode") == null ? "text" : key.Attribute("keycode").Value), PageAction = key.Attribute("pageAction") == null ? null : key.Attribute("pageAction").Value, SwitcherooCode = key.Attribute("switcherooCode") == null ? null : key.Attribute("switcherooCode").Value, Value = key.Attribute("value") != null ? key.Attribute("value").Value : key.Value, ColumnSpan = key.Attribute("colspan") == null ? 2 : int.Parse(key.Attribute("colspan").Value)*2, Column = colIndex, }; if (vkey.KeyType == KeyType.Null) vkey.ColumnSpan = 1; return vkey; }