public void OnKeyDown(Keystroke key) { if (!_active) { return; } if (key == Keystroke.Return) { _scanComplete = true; _active = false; return; } string s = (_manager.Upper)? key.ToString() : key.ToString().ToLower(); if (key == Keystroke.Space) { s = " "; } else if (key == Keystroke.BackSpace) { _scan.Remove(_scan.Length - 1, 1); Console.UpdateInput(_scan.ToString()); return; } _scan.Append(s); Console.UpdateInput(_scan.ToString()); }
public void SequentialGetChildrenTest2() { MusicObject[] testObjects = new MusicObject[5]; testObjects[0] = new Keystroke(Tone.A, 2); testObjects[1] = new Pause(1); testObjects[2] = new ChordVariety(1, 4, 7).WithBaseTone(Tone.E, 2); testObjects[3] = new Pause(1); testObjects[4] = new Keystroke(Tone.D, 2); List <SingleBeat> sSBList = new List <SingleBeat>(); SequentialMusicList sTestList = new SequentialMusicList(testObjects); IOrchestra testOrc = Substitute.For <IOrchestra>(); Instrument i = new Instrument(testOrc, InstrumentType.AcousticBass, new Scale()); sSBList.AddRange(sTestList.GetChildren(i, 1)); int testInt = 0; double testDouble = 0; foreach (SingleBeat sb in sSBList) { if ((sb.ToneStartTime > testDouble)) { testInt++; } testDouble = sb.ToneStartTime; } Assert.IsTrue(testInt == 3); }
public void ParallelGetChildrenTest() { MusicObject[] testObjects = new MusicObject[5]; testObjects[0] = new Keystroke(Tone.A, 2); testObjects[1] = new Pause(1); testObjects[2] = new Keystroke(Tone.B, 3); testObjects[3] = new Pause(1); testObjects[4] = new Keystroke(Tone.D, 5); List <SingleBeat> sTestList = new List <SingleBeat>(); ParallelMusicCollection sTestCollection = new ParallelMusicCollection(testObjects); IOrchestra testOrc = Substitute.For <IOrchestra>(); Instrument i = new Instrument(testOrc, InstrumentType.AcousticBass, new Scale()); sTestList.AddRange(sTestCollection.GetChildren(i, 1)); double testDouble = 1; foreach (SingleBeat sb in sTestList) { if (sb.ToneStartTime != testDouble && (sb.ToneVelocity != 0xff && sb.Tone != 0xff)) { Assert.Fail(); } } }
public void SequentialGetChildrenTest() { MusicObject[] testObjects = new MusicObject[5]; testObjects[0] = new Keystroke(Tone.A, 2); testObjects[1] = new Pause(1); testObjects[2] = new Keystroke(Tone.B, 3); testObjects[3] = new Pause(1); testObjects[4] = new Keystroke(Tone.D, 5); List <SingleBeat> sSBList = new List <SingleBeat>(); SequentialMusicList sTestList = new SequentialMusicList(testObjects); IOrchestra testOrc = Substitute.For <IOrchestra>(); Instrument i = new Instrument(testOrc, InstrumentType.AcousticBass, new Scale()); sSBList.AddRange(sTestList.GetChildren(i, 1)); double testDouble = 0; foreach (SingleBeat sb in sSBList) { if (!(sb.ToneStartTime >= testDouble)) { Assert.Fail(); } testDouble = sb.ToneStartTime; } }
public Result GetKeystroke(DeviceQueryType deviceQueryType, out Keystroke keystroke) { return(ErrorCodeHelper.ToResult( openXinput ? NativeOpenXinput.XInputGetKeystroke(userIndex, (int)deviceQueryType, out keystroke) : NativeXinput.XInputGetKeystroke(userIndex, (int)deviceQueryType, out keystroke) )); }
/// <summary> /// Catch the keystroke event, save it in the buffer and forward the event in /// case a client registered for it. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static async void KeyboardListener_KeyDown(object sender, KeyEventArgs e) { await Task.Run(() => { KeystrokeBuffer.Enqueue(new KeystrokeEvent(e)); Keystroke?.Invoke(new KeystrokeEvent(e)); }); }
public void OnKeyDown(Keystroke key) { if (_keyListeners == null) { return; } _keyListeners(key); }
public void OffsetTest(Tone startTone, int offset, int octaveOffset, Tone expectedTone) { Keystroke k = new Keystroke(startTone, 1); Keystroke expected = new Keystroke(expectedTone, 1); Keystroke result = k.OffsetBy(offset, octaveOffset); Assert.AreEqual(expected.Tone, result.Tone); }
public void Enqueue(Keystroke keystroke) { keystrokesQueue.Enqueue(keystroke); keystrokeWasEnqueued.Set(); if (keystroke.Motion == KeystrokeMotion.Down) { downKeystrokeWasEnqueued.Set(); } }
public void OffsetInScaleTest(Tone startTone, int offset, int octaveOffset, Tone expectedTone) { Scale scale = new Scale(Tone.C, Tone.D, Tone.B); Keystroke k = new Keystroke(startTone, 1); Keystroke expected = new Keystroke(expectedTone, 1); Keystroke result = k.OffsetBy(scale, offset, octaveOffset); Assert.AreEqual(expected.Tone, result.Tone); }
public void SendInput(Keystroke keystroke) { if (keystroke.KeystrokeType == KeystrokeType.KeystrokeDown) { SendScanCode(keystroke.Key); } else { SendKeyUp(keystroke.Key); } }
public void GetChildrenTest(int octave, Tone tone, byte expectedPitch) { IOrchestra o = Substitute.For <IOrchestra>(); Instrument i = new Instrument(o, InstrumentType.AcousticBass, new Scale(), octave); Keystroke n = new Keystroke(tone, 22, 33); SingleBeat actual = n.GetChildren(i, 0).First(); SingleBeat expected = new SingleBeat(i.InstrumentType, expectedPitch, n.Velocity, 0, n.Duration); Assert.AreEqual(actual, expected); }
public override MusicObject Select <T>(Func <T, MusicObject> selector) { Keystroke result = new Keystroke(_rootTone, _duration, _velocity); if (this is T) { return(selector(result as T)); } else { return(result); } }
public void QueueMusicTest() { using (WinmmOut winMM = new WinmmOut(0)) { Orchestra o = new Orchestra(winMM); Keystroke n = new Keystroke(Tone.C, 1000); Instrument i = o.AddInstrument(InstrumentType.AccousticGrandPiano); i.Play(n); Thread.Sleep(5000); } }
public void ParallelMusicCollectionTest() { MusicObject[] testObjects = new MusicObject[5]; testObjects[0] = new Keystroke(Tone.A, 2); testObjects[1] = new Keystroke(Tone.C, 4); testObjects[2] = new Keystroke(Tone.B, 3); testObjects[3] = new Keystroke(Tone.E, 1); testObjects[4] = new Keystroke(Tone.D, 5); ParallelMusicCollection pM = new ParallelMusicCollection(testObjects); Assert.IsTrue(pM.Contains(testObjects[0]) && pM.Contains(testObjects[1]) && pM.Contains(testObjects[2]) && pM.Contains(testObjects[3]) && pM.Contains(testObjects[4])); }
public void SequentialMusicCollectionTest() { MusicObject[] testObjects = new MusicObject[5]; testObjects[0] = new Keystroke(Tone.A, 2); testObjects[1] = new Keystroke(Tone.C, 4); testObjects[2] = new Keystroke(Tone.B, 3); testObjects[3] = new Keystroke(Tone.E, 1); testObjects[4] = new Keystroke(Tone.D, 5); SequentialMusicList sTest = new SequentialMusicList(testObjects); Assert.IsTrue(sTest.Contains(testObjects[0]) && sTest.Contains(testObjects[1]) && sTest.Contains(testObjects[2]) && sTest.Contains(testObjects[3]) && sTest.Contains(testObjects[4])); }
public static RemoteDesktopKeystrokeInfo GetKeystroke(Keystroke keystroke) { RemoteDesktopKeystrokeInfo info = new RemoteDesktopKeystrokeInfo(); switch (keystroke) { case Keystroke.CtrlAltDel: info.ArrayKeyUp = new bool[] { false, false, false, true, true, true, }; info.KeyData = new int[] { 0x1d, 0x38, 0x53, 0x53, 0x38, 0x1d }; break; } return(info); }
private void BuildStrokeList(string text) { _strokes = new List <Keystroke>(); foreach (char c in text) { // // For capital letters or shifted symbols, we need to depress Shift first // (and release it when done). // bool shifted = _shiftedKeyMap.ContainsKey(c); AltoKey charKey; if (shifted) { Keystroke shift = new Keystroke(StrokeType.KeyDown, AltoKey.RShift); _strokes.Add(shift); charKey = _shiftedKeyMap[c]; } else { if (_unmodifiedKeyMap.ContainsKey(c)) { charKey = _unmodifiedKeyMap[c]; } else { // Ignore this keystroke. continue; } } _strokes.Add(new Keystroke(StrokeType.KeyDown, charKey)); _strokes.Add(new Keystroke(StrokeType.KeyUp, charKey)); if (shifted) { Keystroke unshift = new Keystroke(StrokeType.KeyUp, AltoKey.RShift); _strokes.Add(unshift); } } if (_cr) { // Add a Return keystroke to the end _strokes.Add(new Keystroke(StrokeType.KeyDown, AltoKey.Return)); _strokes.Add(new Keystroke(StrokeType.KeyUp, AltoKey.Return)); } }
public void StartBind() { //== Prepare Keystroke Keystroke CtrlIns = new Keystroke(Keys.Insert, Keys.Control); Keystroke CtrlDel = new Keystroke(Keys.Delete, Keys.Control); Keystroke F2 = new Keystroke(Keys.F2, Keys.None); Keystroke F5 = new Keystroke(Keys.F5, Keys.None); Keystroke Enter = new Keystroke(Keys.Enter, Keys.None); //Keystroke Esc = new Keystroke(Keys.Escape, Keys.None); //== Prepare action. ActionEvent actionAddNewRow = new ActionEvent(); actionAddNewRow.Action += actionAddNewRow_Action; ActionEvent actionRemoveRow = new ActionEvent(); actionRemoveRow.Action += actionRemoveRow_Action; ActionEvent actionF5 = new ActionEvent(); actionF5.Action += actionF5_Action; //ActionEvent actionEsc = new ActionEvent(); //actionEsc.Action += actionEsc_Action; //== Start bind keystroke and action. InputMap im = m_owner.GetInputMap(InputMapMode.WhenFocused); InputMap imx = m_owner.GetInputMap(InputMapMode.WhenAncestorOfFocused); ActionMap am = m_owner.GetActionMap(); im.Put(CtrlIns, eAction.AddRow.ToString()); im.Put(CtrlDel, eAction.RemoveRow.ToString()); im.Put(F2, SpreadActions.StopEditing); im.Put(F5, "F5"); im.Put(Enter, SpreadActions.StartEditing); //imx.Put(Esc, "Esc"); am.Put(eAction.AddRow.ToString(), actionAddNewRow); am.Put(eAction.RemoveRow.ToString(), actionRemoveRow); am.Put("F5", actionF5); //am.Put("Esc", actionEsc); m_bBind = true; }
private void ParseKeystrokeGestures(int userIndex, Keystroke keystroke) { if (keystroke.Flags == KeyStrokeFlags.KeyDown) { return; } foreach (var button in EnumUtils.GetValues <GamepadVirtualKey>()) { if ((keystroke.VirtualKey & button) != 0) { HandleGesture(GamepadButtonGesture.Create(userIndex, button)); } } }
private void CommonKeys(SmoothListbox list, ref Keystroke current) { foreach (var key in _keys) { switch (key) { case Keys.Cancel: case Keys.Escape: var view = ActiveView as IHistoryEntry; if (view != null) { var stack = view.Stack; stack.HandleBackLink(view.BackLink, view.OutputPane); _keys.Clear(); current = null; } break; case Keys.PageUp: if (list != null) { list.ScrollPageUp(true); _keys.Clear(); current = null; } break; case Keys.PageDown: if (list != null) { list.ScrollPageDown(true); _keys.Clear(); current = null; } break; case Keys.Play: iApp.Navigate("audio://?command=pause"); break; } if (current == null) { break; } } }
private static void Notify(string message, bool isNew = false) { sw.Stop(); if (sw.ElapsedMilliseconds > 1000 || current == null || isNew || (!isNew && beforeIsNew) || current.Keys.Length >= 10) { current = new Keystroke { Keys = message }; _visualizer.AddNotification(current); sw.Reset(); sw.Start(); beforeIsNew = isNew; return; } current.Keys += message; sw.Reset(); sw.Start(); beforeIsNew = isNew; }
private void ManageKeyUpDown(Keystroke keystroke, Action up, Action down) { if (!IsEnabled) { return; } if (keystroke.Flags.HasFlag(KeyStrokeFlags.KeyDown)) { down?.Invoke(); } else if (keystroke.Flags.HasFlag(KeyStrokeFlags.KeyUp)) { up?.Invoke(); } else { Debug.WriteLine("Azione non definita"); } }
/// <summary> /// Called when key down. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="KeyEventArgs"/> instance containing the event data.</param> private void OnKeyDown(object sender, KeyEventArgs e) { Instructions.Instruction newInstruction; Keys key = e.KeyCode; //Console.WriteLine(key); if (key == MainWindow.RECORD_HOTKEY || key == MainWindow.PLAY_HOTKEY) { return; } bool recordText = false; string converted = WindowsKeyExtension.ToLiteral(WindowsKeyExtension.KeyCodeToUnicode(key)); if (!recordText || isCtrlDown || isAltDown || converted.Length <= 0 || !((converted[0] >= 'A' && converted[0] <= 'Z') || (converted[0] >= 'a' && converted[0] <= 'z') || (converted[0] >= '0' && converted[0] <= '9' && !isShiftDown))) { VirtualKeyCode virtualKeyCode = (VirtualKeyCode)(int)key; newInstruction = new Keystroke(virtualKeyCode, shift: isShiftDown, ctrl: isCtrlDown, alt: isAltDown); } else { if (isShiftDown) { converted = converted.ToUpperInvariant(); } newInstruction = new Text(converted, ctrl: isCtrlDown, alt: isAltDown); } bool hotkeyChanged = SetHotkeys(key, true); if (hotkeyChanged) { return; } AddOrIncrement(newInstruction); }
/// <summary> /// Returns the full contents of this MusicObject as SingleBeats. /// These are modified by the octave of the instrument that played them. /// </summary> /// <param name="playedBy">The instrument that requests the children.</param> /// <param name="startTime">The time at which the SingleBeats should start playing.</param> /// <returns>The full contents of this MusicObject as SingleBeats.</returns> internal override IEnumerable <SingleBeat> GetChildren(Instrument playedBy, double startTime) { Scale scale = playedBy.Scale; foreach (int t in _toneSteps) { int offset = t - 1; //Chords are defined with 1 being the first element. Not very programmer-like, we know. //New Keystroke with correct tone. Keystroke k = new Keystroke ( scale[scale.Interval(_rootTone) + offset], _duration, _velocity ); yield return(k.GetChildren(playedBy, startTime) //Tone conversion handled by Keystroke class. .First()); //Keystroke is a leaf so there will only be one element in the list. Only want that. } yield return(new Pause(_duration).GetChildren(playedBy, startTime).First()); //Pause only returns one child, we only want that }
private void KeystrokeMaker() { for (int i = 0; i < keystrokeEventsBuffer.Count; i++) { if (keystrokeEventsBuffer[i] != null) { if (keystrokeEventsBuffer[i].Type == KeystrokeType.KeyDown) { Keystroke keystroke = new Keystroke(); keystroke.Key = keystrokeEventsBuffer[i].Key; keystroke.KeyDown = keystrokeEventsBuffer[i].EventTime; uniqueKeyCount[keystroke.Key.KeyIndex]++; for (int j = i + 1; j < keystrokeEventsBuffer.Count; j++) { if (keystrokeEventsBuffer[j] != null) { if (keystrokeEventsBuffer[j].Key.KeyIndex == keystroke.Key.KeyIndex) { if (keystrokeEventsBuffer[j].Type == KeystrokeType.KeyUp) { keystroke.KeyUp = keystrokeEventsBuffer[j].EventTime; keyboardData.StrokeHoldTimes += keystroke.HoldTime; keystrokes.Add(keystroke); break; } else { keystrokeEventsBuffer[j] = null; } } } } } } } keystrokeEventsBuffer.Clear(); //Console.WriteLine(keystrokes.Count); }
public override void Replay(AltoSystem system, ExecutionController controller) { if (_currentStroke >= _strokes.Count) { _completed = true; } else { Keystroke stroke = _strokes[_currentStroke++]; if (stroke.Type == StrokeType.KeyDown) { system.Keyboard.KeyDown(stroke.Key); } else { system.Keyboard.KeyUp(stroke.Key); } // Delay 50ms before the next key _timestamp = 50 * Conversion.MsecToNsec; } }
uint XInputGetKeystroke_Hooked(int dwUserIndex, int dwReserved, out Keystroke pKeystroke) { pKeystroke = new Keystroke(); var controller = new Controller((UserIndex)dwUserIndex); if (controller.IsConnected) { try { var result = controller.GetKeystroke(DeviceQueryType.Any, out pKeystroke); return((uint)result.Code); } catch { return(ERROR_DEVICE_NOT_CONNECTED); } } else { pKeystroke.UserIndex = UserIndex.One; } return(ERROR_SUCCESS); }
private void ManageSpeed(int x, Keystroke keystroke) { if (!IsEnabled) { return; } var lastSpeed = Speed; if (keystroke.Flags.HasFlag(KeyStrokeFlags.KeyUp)) { if (x < 0 && Speed > 1) { Speed -= 1; } else if (x > 0 && Speed < 5) { Speed += 1; } if (Speed != lastSpeed) { Debug.WriteLine($"Speed = {Speed}"); } } }
static void Surface_KeystrokeEvent(Keystroke keystroke, MegaDungeonUI ui) { // Console.WriteLine($"{keystroke.Modifier}{keystroke.Key}"); ui.AcceptInput(keystroke); }