void SaveLastKeyPressed(PhysicalKey key) { Handedness handedness = key.ParentSection.Handedness; switch (handedness) { case Handedness.Left: lastLeftKeyPressed = key; timeOfLastLeftKeyPress = DateTime.Now; if (timeOfLastRightKeyPress > timeOfLastAmbidextrousKeyPressed) // Both right-handed and left-handed keys have been pressed more recently than the last ambidextrous key was hit. { lastAmbidextrousKeyPressed = null; } break; case Handedness.Right: lastRightKeyPressed = key; timeOfLastRightKeyPress = DateTime.Now; if (timeOfLastLeftKeyPress > timeOfLastAmbidextrousKeyPressed) // Both right-handed and left-handed keys have been pressed more recently than the last ambidextrous key was hit. { lastAmbidextrousKeyPressed = null; } break; case Handedness.Both: lastAmbidextrousKeyPressed = key; timeOfLastAmbidextrousKeyPressed = DateTime.Now; break; } }
public double GetMouseToKeyboardTransitionCost(KeyDownEvent keyDownEvent) { PhysicalKey key = FindKey(keyDownEvent.Data); if (key != null) { KeyboardSection parentSection = key.ParentSection; if (parentSection.Handedness == Handedness.Right) { lastMouseHandedAction = ActionType.Keyboard; if (MousePad == null) { throw new Exception("MousePad not specified."); } if (mousePadCenter.X == double.MinValue) { CalculateMousePadCenterPoint(); } double travelDistance = MillerComplexity.GetDistance(parentSection.Center, mousePadCenter); double targetApproachWidth = MillerComplexity.GetTargetApproachWidth(key.Size.Width, key.Size.Height); return(MillerComplexity.GetTargetPressScore(travelDistance, targetApproachWidth)); } } return(0); }
public void PrepareForAnalysis() { lastLeftKeyPressed = null; lastRightKeyPressed = null; lastAmbidextrousKeyPressed = null; lastMouseHandedAction = ActionType.None; }
double GetDistanceFromLastAmbidextrousKey(PhysicalKey key) { if (lastAmbidextrousKeyPressed == null) { return(double.MaxValue); } else { return(GetApproximateDistanceBetweenKeys(key, lastAmbidextrousKeyPressed)); } }
double GetDistanceToLastRightHandedKey(PhysicalKey key) { if (lastRightKeyPressed == null) { return(GetApproximateDistanceToKey(homeKeysRight, key)); } else { return(GetApproximateDistanceBetweenKeys(key, lastRightKeyPressed)); } }
double CalculateCost(PhysicalKey key) { if (KeyIsARepeat(key)) { return(MillerComplexity.GetCostOfRepeatHit(key.EffectiveTargetApproachWidth)); } const double DBL_AverageDistanceToSpaceBarWhileHandsNearHomeKeys = 1.4; /* cm */ if (SpaceBarHitWhileHandsAtHomeRow(key)) { return(MillerComplexity.GetTargetPressScore(DBL_AverageDistanceToSpaceBarWhileHandsNearHomeKeys, key.EffectiveTargetApproachWidth)); // Space bar hit and at least one hand is near the home key row position. } return(MillerComplexity.GetTargetPressScore(GetShortestDistanceToKey(key), key.EffectiveTargetApproachWidth)); }
public virtual double GetKeyCost(string keyName) { PhysicalKey key = FindKey(keyName); double cost = 0; if (key != null) { if (KeyHasSameHandednessAsMouse(key)) { lastMouseHandedAction = ActionType.Keyboard; } cost = CalculateCost(key); SaveLastKeyPressed(key); } else { //throw new Exception("key not found: " + keyName); } return(cost); }
double GetShortestDistanceToKey(PhysicalKey key) { double distanceToLastSameHandedKey = double.MaxValue; double distanceToAmbidextrousKey = GetDistanceFromLastAmbidextrousKey(key); // Find the closest section (holding a previously-hit key) to the specified key... if (key.ParentSection.Handedness == Handedness.Left) { distanceToLastSameHandedKey = GetDistanceToLastLeftHandedKey(key); } else if (key.ParentSection.Handedness == Handedness.Right) { distanceToLastSameHandedKey = GetDistanceToLastRightHandedKey(key); } else if (key.ParentSection.Handedness == Handedness.Both) { double distanceFromLastLeftHandedKey = GetDistanceToLastLeftHandedKey(key); double distanceFromLastRightHandedKey = GetDistanceToLastRightHandedKey(key); double distanceFromNearestHand = Math.Min(distanceToAmbidextrousKey, Math.Min(distanceFromLastLeftHandedKey, distanceFromLastRightHandedKey)); if (distanceFromNearestHand < double.MaxValue) { return(distanceFromNearestHand); } } double smallestDistance; if (distanceToLastSameHandedKey == double.MaxValue && distanceToAmbidextrousKey == double.MaxValue) { smallestDistance = DBL_MinimumDistanceBetweenKeys; } else { smallestDistance = Math.Min(distanceToLastSameHandedKey, distanceToAmbidextrousKey); } return(smallestDistance); }
bool KeyHasSameHandednessAsMouse(PhysicalKey key) { return(key.ParentSection.Handedness == MousePadPosition); }
bool SpaceBarHitWhileHandsAtHomeRow(PhysicalKey key) { return(key.Name == "Space" && (lastLeftKeyPressed == null || lastRightKeyPressed == null || lastLeftKeyPressed.ParentSection == homeKeysLeft || lastRightKeyPressed.ParentSection == homeKeysRight)); }
bool KeyIsARepeat(PhysicalKey key) { return(key == lastLeftKeyPressed || key == lastRightKeyPressed || key == lastAmbidextrousKeyPressed); }
/// <summary> /// Determines the approximate travel distance between keys by measuring the travel distance /// between the parenting sections of the two keys. /// </summary> double GetApproximateDistanceBetweenKeys(PhysicalKey key1, PhysicalKey key2) { KeyboardSection section = key2.ParentSection; return(GetApproximateDistanceToKey(section, key1)); }
/// <summary> /// Returns the distance between the center of the specified section to the center of the section /// holding the specified key. /// </summary> double GetApproximateDistanceToKey(KeyboardSection section, PhysicalKey key1) { double distanceBetweenPoints = GetDistanceBetweenPoints(key1.ParentSection.Center, section.Center); return(Math.Max(distanceBetweenPoints, DBL_MinimumDistanceBetweenKeys)); }