public KeyPressReadingSmallWindow(bool supportIndefinite = true) { InitializeComponent(); ComboBoxPressTimes.SelectedItem = KeyPressLength.ThirtyTwoMilliSec; _keyPressLength = KeyPressLength.ThirtyTwoMilliSec; _supportIndefinite = supportIndefinite; }
public KeyPressReadingSmallWindow(KeyPressLength keyPressLength, string keyPress, bool supportIndefinite = true) { InitializeComponent(); TextBoxKeyPress.Text = keyPress; ComboBoxPressTimes.SelectedItem = keyPressLength; _keyPressLength = keyPressLength; _supportIndefinite = supportIndefinite; }
public OSKeyPress(string keycodes, KeyPressLength keyPressLength = KeyPressLength.FiftyMilliSec, string information = null) { var keyInfo = new KeyPressInfo(); keyInfo.VirtualKeyCodes = SplitStringKeyCodes(keycodes); _sortedList.Add(GetNewKeyValue(), keyInfo); keyInfo.LengthOfKeyPress = keyPressLength; _information = information; }
public KeyPress(string keycodes, KeyPressLength keyPressLength = KeyPressLength.FiftyMilliSec, string description = null) { try { var keyPressInfo = new KeyPressInfo { VirtualKeyCodes = SplitStringKeyCodes(keycodes) }; _sortedKeyPressInfoList.Add(GetNewKeyValue(), keyPressInfo); keyPressInfo.LengthOfKeyPress = keyPressLength; _description = description; } catch (Exception e) { throw new Exception("Error creating KeyPress object. " + e.Message); } }
private void ComboBoxPressTimes_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (!_loaded) { return; } var tmpKeyPressLength = (KeyPressLength)ComboBoxPressTimes.SelectedItem; if (tmpKeyPressLength != _keyPressLength) { _keyPressLength = tmpKeyPressLength; _isDirty = true; } SetFormState(); } catch (Exception ex) { Common.ShowErrorMessageBox(ex); } }
public override void AddOrUpdateKeyStrokeBinding(PanelSwitchOnOff panelSwitchOnOff, string keyPress, KeyPressLength keyPressLength) { }
public void AddOrUpdateSingleKeyBinding(MultiPanelPZ70Knobs multiPanelPZ70Knob, string keys, KeyPressLength keyPressLength, bool whenTurnedOn) { if (string.IsNullOrEmpty(keys)) { RemoveMultiPanelKnobFromList(ControlListPZ70.KEYS, multiPanelPZ70Knob, whenTurnedOn); SetIsDirty(); return; } //This must accept lists var found = false; foreach (var knobBinding in _knobBindings) { if (knobBinding.DialPosition == _pz70DialPosition && knobBinding.MultiPanelPZ70Knob == multiPanelPZ70Knob && knobBinding.WhenTurnedOn == whenTurnedOn) { if (string.IsNullOrEmpty(keys)) { knobBinding.OSKeyPress = null; } else { knobBinding.OSKeyPress = new KeyPress(keys, keyPressLength); } found = true; } } if (!found && !string.IsNullOrEmpty(keys)) { var knobBinding = new KeyBindingPZ70(); knobBinding.MultiPanelPZ70Knob = multiPanelPZ70Knob; knobBinding.DialPosition = _pz70DialPosition; knobBinding.OSKeyPress = new KeyPress(keys, keyPressLength); knobBinding.WhenTurnedOn = whenTurnedOn; _knobBindings.Add(knobBinding); } _knobBindings = KeyBindingPZ70.SetNegators(_knobBindings); SetIsDirty(); }
/* * DO NOT USE BAD CODING /JERKER * private static void WaiatMilliSeconds(KeyPressLength keyPressLength) * { * var once = true; * var startMilliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; * var nowMilliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; * while (nowMilliseconds - startMilliseconds < (int)keyPressLength) * { * if (Common.Debug && once) * { * Common.DebugP("Waiting " + keyPressLength + " ms."); * once = false; * } * nowMilliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; * } * } */ /* * SendInput är den korrekta funktionen att använda idag (13.1.2014) då keybd_event inte längre ska användas. * DCS dock fungerar inte med SendInput, LCONTROL,RCONTROL,LSHIFT,LALT,RSHIFT,RALT tas inte emot på korrekt sätt. * * */ public void SendKeys(KeyPressLength breakLength, VirtualKeyCode[] virtualKeyCodes, KeyPressLength keyPressLength) { var keyPressLengthTimeConsumed = 0; var breakLengthConsumed = 0; while (breakLengthConsumed < (int)breakLength) { Thread.Sleep(50); breakLengthConsumed += 50; if (AbortThread()) { return; } } var inputs = new WindowsAPI.INPUT[virtualKeyCodes.Count()]; var modifierCount = 0; foreach (var virtualKeyCode in virtualKeyCodes) { if (Common.IsModifierKey(virtualKeyCode)) { modifierCount++; } } //Add modifiers for (var i = 0; i < virtualKeyCodes.Count(); i++) { var virtualKeyCode = virtualKeyCodes[i]; if (Common.IsModifierKey(virtualKeyCode)) { Common.DebugP("INSERTING [] AT " + i + " total position are " + inputs.Count()); inputs[i].type = WindowsAPI.INPUT_KEYBOARD; inputs[i].InputUnion.ki.time = 0; inputs[i].InputUnion.ki.dwFlags = WindowsAPI.KEYEVENTF_SCANCODE; Common.DebugP(Enum.GetName(typeof(VirtualKeyCode), virtualKeyCode) + " is MODIFIER = " + Common.IsExtendedKey(virtualKeyCode)); if (Common.IsExtendedKey(virtualKeyCode)) { inputs[i].InputUnion.ki.dwFlags |= WindowsAPI.KEYEVENTF_EXTENDEDKEY; } inputs[i].InputUnion.ki.wVk = 0; Common.DebugP("***********\nMapVirtualKey returned " + Enum.GetName(typeof(VirtualKeyCode), virtualKeyCode) + " : " + WindowsAPI.MapVirtualKey((uint)virtualKeyCode, 0) + "\n************"); inputs[i].InputUnion.ki.wScan = (ushort)WindowsAPI.MapVirtualKey((uint)virtualKeyCode, 0); inputs[i].InputUnion.ki.dwExtraInfo = WindowsAPI.GetMessageExtraInfo(); } i++; } //[x][x] [] [] // 0 1 2 3 // 1 2 3 4 //Add normal keys for (var i = modifierCount; i < virtualKeyCodes.Count(); i++) { var virtualKeyCode = virtualKeyCodes[i]; if (!Common.IsModifierKey(virtualKeyCode)) { Common.DebugP("INSERTING [] AT " + i + " total position are " + inputs.Count()); inputs[i].type = WindowsAPI.INPUT_KEYBOARD; inputs[i].InputUnion.ki.time = 0; inputs[i].InputUnion.ki.dwFlags = WindowsAPI.KEYEVENTF_SCANCODE; //Common.DebugP(Enum.GetName(typeof(VirtualKeyCode), virtualKeyCodeHolder.VirtualKeyCode) + " is NOT MODIFIER"); inputs[i].InputUnion.ki.wVk = 0; Common.DebugP("***********\nMapVirtualKey returned " + Enum.GetName(typeof(VirtualKeyCode), virtualKeyCode) + " : " + WindowsAPI.MapVirtualKey((uint)virtualKeyCode, 0) + "\n************"); inputs[i].InputUnion.ki.wScan = (ushort)WindowsAPI.MapVirtualKey((uint)virtualKeyCode, 0); inputs[i].InputUnion.ki.dwExtraInfo = WindowsAPI.GetMessageExtraInfo(); i++; } } WindowsAPI.SendInput((uint)inputs.Count(), inputs, Marshal.SizeOf(typeof(WindowsAPI.INPUT))); /*if (keyPressLength == KeyPressLength.Indefinite) * { * return; * }*/ while (keyPressLengthTimeConsumed < (int)keyPressLength) { Thread.Sleep(50); keyPressLengthTimeConsumed += 50; if (AbortThread()) { //If we are to cancel the whole operation. Release pressed keys ASAP and exit. break; } } for (var i = 0; i < inputs.Count(); i++) { inputs[i].InputUnion.ki.dwFlags |= WindowsAPI.KEYEVENTF_KEYUP; } Array.Reverse(inputs); //Release same keys WindowsAPI.SendInput((uint)inputs.Count(), inputs, Marshal.SizeOf(typeof(WindowsAPI.INPUT))); }
private void KeyBdEventAPI(KeyPressLength breakLength, VirtualKeyCode[] virtualKeyCodes, KeyPressLength keyPressLength) { var keyPressLengthTimeConsumed = 0; var breakLengthConsumed = 0; /* * //keybd_event * http://msdn.microsoft.com/en-us/library/windows/desktop/ms646304%28v=vs.85%29.aspx */ while (breakLengthConsumed < (int)breakLength) { Thread.Sleep(50); breakLengthConsumed += 50; if (AbortThread()) { return; } } //Press modifiers for (var i = 0; i < virtualKeyCodes.Count(); i++) { var virtualKeyCode = virtualKeyCodes[i]; if (Common.IsModifierKey(virtualKeyCode)) { Common.DebugP(Enum.GetName(typeof(VirtualKeyCode), virtualKeyCode) + " is MODIFIER = " + Common.IsExtendedKey(virtualKeyCode)); if (Common.IsExtendedKey(virtualKeyCode)) { WindowsAPI.keybd_event((byte)virtualKeyCode, (byte)WindowsAPI.MapVirtualKey((uint)virtualKeyCode, 0), (int)WindowsAPI.KEYEVENTF_EXTENDEDKEY | 0, 0); } else { WindowsAPI.keybd_event((byte)virtualKeyCode, (byte)WindowsAPI.MapVirtualKey((uint)virtualKeyCode, 0), 0, 0); } } } //Press normal keys for (var i = 0; i < virtualKeyCodes.Count(); i++) { var virtualKeyCode = virtualKeyCodes[i]; if (!Common.IsModifierKey(virtualKeyCode)) { WindowsAPI.keybd_event((byte)virtualKeyCode, (byte)WindowsAPI.MapVirtualKey((uint)virtualKeyCode, 0), 0, 0); } } /*if (keyPressLength == KeyPressLength.Indefinite) * { * return; * }*/ while (keyPressLengthTimeConsumed < (int)keyPressLength) { Thread.Sleep(50); keyPressLengthTimeConsumed += 50; if (AbortThread()) { //If we are to cancel the whole operation. Release pressed keys ASAP and exit. break; } } //Release normal keys for (var i = 0; i < virtualKeyCodes.Count(); i++) { var virtualKeyCode = virtualKeyCodes[i]; if (!Common.IsModifierKey(virtualKeyCode)) { WindowsAPI.keybd_event((byte)virtualKeyCode, (byte)WindowsAPI.MapVirtualKey((uint)virtualKeyCode, 0), (int)WindowsAPI.KEYEVENTF_KEYUP, 0); } } //Release modifiers for (var i = 0; i < virtualKeyCodes.Count(); i++) { var virtualKeyCode = virtualKeyCodes[i]; if (Common.IsModifierKey(virtualKeyCode)) { Common.DebugP(Enum.GetName(typeof(VirtualKeyCode), virtualKeyCode) + " is MODIFIER = " + Common.IsExtendedKey(virtualKeyCode)); if (Common.IsExtendedKey(virtualKeyCode)) { WindowsAPI.keybd_event((byte)virtualKeyCode, (byte)WindowsAPI.MapVirtualKey((uint)virtualKeyCode, 0), (int)(WindowsAPI.KEYEVENTF_EXTENDEDKEY | WindowsAPI.KEYEVENTF_KEYUP), 0); } else { WindowsAPI.keybd_event((byte)virtualKeyCode, (byte)WindowsAPI.MapVirtualKey((uint)virtualKeyCode, 0), (int)WindowsAPI.KEYEVENTF_KEYUP, 0); } } } }
public void AddOrUpdateSingleKeyBinding(RadioPanelPZ69KnobsEmulator radioPanelPZ69Knob, string keys, KeyPressLength keyPressLength, bool whenTurnedOn) { var pz69DialPosition = GetDial(radioPanelPZ69Knob); if (string.IsNullOrEmpty(keys)) { var tmp = new RadioPanelPZ69KeyOnOff(radioPanelPZ69Knob, whenTurnedOn); ClearAllBindings(pz69DialPosition, tmp); return; } var found = false; foreach (var keyBinding in _keyBindings) { if (keyBinding.RadioPanelPZ69Key == radioPanelPZ69Knob && keyBinding.WhenTurnedOn == whenTurnedOn && keyBinding.DialPosition == pz69DialPosition) { if (string.IsNullOrEmpty(keys)) { keyBinding.OSKeyPress = null; } else { keyBinding.OSKeyPress = new OSKeyPress(keys, keyPressLength); keyBinding.WhenTurnedOn = whenTurnedOn; } found = true; } } if (!found && !string.IsNullOrEmpty(keys)) { var keyBinding = new KeyBindingPZ69DialPosition(); keyBinding.RadioPanelPZ69Key = radioPanelPZ69Knob; keyBinding.DialPosition = pz69DialPosition; keyBinding.OSKeyPress = new OSKeyPress(keys, keyPressLength); keyBinding.WhenTurnedOn = whenTurnedOn; _keyBindings.Add(keyBinding); } Common.DebugP("RadioPanelPZ69FullEmulator _keyBindings : " + _keyBindings.Count); IsDirtyMethod(); }
public void AddOrUpdateSingleKeyBinding(SwitchPanelPZ55Keys switchPanelPZ55Key, string keys, KeyPressLength keyPressLength, bool whenTurnedOn = true) { if (string.IsNullOrEmpty(keys)) { var tmp = new SwitchPanelPZ55KeyOnOff(switchPanelPZ55Key, whenTurnedOn); ClearAllBindings(tmp); return; } var found = false; foreach (var keyBinding in _keyBindings) { if (keyBinding.SwitchPanelPZ55Key == switchPanelPZ55Key && keyBinding.WhenTurnedOn == whenTurnedOn) { if (string.IsNullOrEmpty(keys)) { keyBinding.OSKeyPress = null; } else { keyBinding.OSKeyPress = new OSKeyPress(keys, keyPressLength); keyBinding.WhenTurnedOn = whenTurnedOn; } found = true; } } if (!found && !string.IsNullOrEmpty(keys)) { var keyBinding = new KeyBindingPZ55(); keyBinding.SwitchPanelPZ55Key = switchPanelPZ55Key; keyBinding.OSKeyPress = new OSKeyPress(keys, keyPressLength); keyBinding.WhenTurnedOn = whenTurnedOn; _keyBindings.Add(keyBinding); } Common.DebugP("SwitchPanelPZ55 _keyBindings : " + _keyBindings.Count); IsDirtyMethod(); }
internal void CheckContextMenuItems(KeyPressLength keyPressLength, ContextMenu contextMenu) { try { foreach (MenuItem item in contextMenu.Items) { item.IsChecked = false; } foreach (MenuItem item in contextMenu.Items) { if (item.Name == "contextMenuItemFiftyMilliSec" && keyPressLength == KeyPressLength.FiftyMilliSec) { item.IsChecked = true; } else if (item.Name == "contextMenuItemHalfSecond" && keyPressLength == KeyPressLength.HalfSecond) { item.IsChecked = true; } else if (item.Name == "contextMenuItemSecond" && keyPressLength == KeyPressLength.Second) { item.IsChecked = true; } else if (item.Name == "contextMenuItemSecondAndHalf" && keyPressLength == KeyPressLength.SecondAndHalf) { item.IsChecked = true; } else if (item.Name == "contextMenuItemTwoSeconds" && keyPressLength == KeyPressLength.TwoSeconds) { item.IsChecked = true; } else if (item.Name == "contextMenuItemThreeSeconds" && keyPressLength == KeyPressLength.ThreeSeconds) { item.IsChecked = true; } else if (item.Name == "contextMenuItemFourSeconds" && keyPressLength == KeyPressLength.FourSeconds) { item.IsChecked = true; } else if (item.Name == "contextMenuItemFiveSecs" && keyPressLength == KeyPressLength.FiveSecs) { item.IsChecked = true; } else if (item.Name == "contextMenuItemFifteenSecs" && keyPressLength == KeyPressLength.FifteenSecs) { item.IsChecked = true; } else if (item.Name == "contextMenuItemTenSecs" && keyPressLength == KeyPressLength.TenSecs) { item.IsChecked = true; } else if (item.Name == "contextMenuItemTwentySecs" && keyPressLength == KeyPressLength.TwentySecs) { item.IsChecked = true; } else if (item.Name == "contextMenuItemThirtySecs" && keyPressLength == KeyPressLength.ThirtySecs) { item.IsChecked = true; } else if (item.Name == "contextMenuItemFortySecs" && keyPressLength == KeyPressLength.FortySecs) { item.IsChecked = true; } else if (item.Name == "contextMenuItemSixtySecs" && keyPressLength == KeyPressLength.SixtySecs) { item.IsChecked = true; } } } catch (Exception ex) { Common.ShowErrorMessageBox(21999, ex); } }
public void AddOrUpdateSingleKeyBinding(TPMPanelSwitches tpmPanelSwitch, string keys, KeyPressLength keyPressLength, bool whenTurnedOn = true) { if (string.IsNullOrEmpty(keys)) { var tmp = new TPMPanelSwitch.TPMPanelSwitchOnOff(tpmPanelSwitch, whenTurnedOn); ClearAllBindings(tmp); return; } var found = false; foreach (var keyBinding in _keyBindings) { if (keyBinding.TPMSwitch == tpmPanelSwitch && keyBinding.WhenTurnedOn == whenTurnedOn) { if (string.IsNullOrEmpty(keys)) { keyBinding.OSKeyPress = null; } else { keyBinding.OSKeyPress = new OSKeyPress(keys, keyPressLength); keyBinding.WhenTurnedOn = whenTurnedOn; } found = true; } } if (!found && !string.IsNullOrEmpty(keys)) { var keyBinding = new KeyBindingTPM(); keyBinding.TPMSwitch = tpmPanelSwitch; keyBinding.OSKeyPress = new OSKeyPress(keys, keyPressLength); keyBinding.WhenTurnedOn = whenTurnedOn; _keyBindings.Add(keyBinding); } Common.DebugP("TPMPanel _keyBindings : " + _keyBindings.Count); IsDirtyMethod(); }
public abstract void AddOrUpdateKeyStrokeBinding(PanelSwitchOnOff panelSwitchOnOff, string keyPress, KeyPressLength keyPressLength);
public void AddOrUpdateSingleKeyBinding(MultiPanelPZ70Knobs multiPanelPZ70Knob, string keys, KeyPressLength keyPressLength, bool whenTurnedOn = true) { //This must accept lists var found = false; foreach (var knobBinding in _knobBindings) { if (knobBinding.MultiPanelPZ70Knob == multiPanelPZ70Knob && knobBinding.WhenTurnedOn == whenTurnedOn) { if (string.IsNullOrEmpty(keys)) { knobBinding.OSKeyPress = null; } else { knobBinding.OSKeyPress = new OSKeyPress(keys, keyPressLength); knobBinding.WhenTurnedOn = whenTurnedOn; } found = true; } } if (!found && !string.IsNullOrEmpty(keys)) { var knobBinding = new KnobBindingPZ70(); knobBinding.MultiPanelPZ70Knob = multiPanelPZ70Knob; knobBinding.OSKeyPress = new OSKeyPress(keys, keyPressLength); knobBinding.WhenTurnedOn = whenTurnedOn; _knobBindings.Add(knobBinding); } Common.DebugP("MultiPanelPZ70 _knobBindings : " + _knobBindings.Count); IsDirtyMethod(); }