public void onKeyDown(KeyEventArgs e) { if (motorKeys.Contains(e.Key)) // W,A,S,D are used for direction controlling. { MotorValue.acceleration_time = 0; MotorValue.acceleration_distance = 0; if (Keyboard.IsKeyDown(Key.D)) { MotorValue.direction_way = "Right"; MotorValue.direction_angle = 1; } else if (Keyboard.IsKeyDown(Key.A)) { MotorValue.direction_way = "Left"; MotorValue.direction_angle = 1; } if (Keyboard.IsKeyDown(Key.W)) { MotorValue.acceleration_way = "Forward"; MotorValue.acceleration_angle = 1; } else if (Keyboard.IsKeyDown(Key.D)) { MotorValue.acceleration_way = "Backward"; MotorValue.acceleration_angle = 1; } _motorControl.SendCommand(); } if (Keyboard.IsKeyDown(Key.Space) && !HornValue.isPressed) //Space is used for horn. { HornValue.isPressed = true; HornValue.time = 0; _hornControl.SendCommand(); } if (Keyboard.IsKeyDown(Key.RightShift) && !BrakeValue.IsPressed) // Right Shift is used for brake. { BrakeValue.IsPressed = true; _brakeControl.SendCommand(); } }
public void Hoot(string text) { if (text.StartsWith("sound")) { int time = Convert.ToInt32(ExtractNumber(Regex.Match(text, @"sound the horn for (.+) secon(d|ds)").Groups[1].ToString())); HornValue.isPressed = true; HornValue.time = time; _hornControl.SendCommand(); } else if (text.StartsWith("hoot")) { HornValue.isPressed = true; HornValue.time = 0; _hornControl.SendCommand(); } else { HornValue.isPressed = false; HornValue.time = 0; _hornControl.SendCommand(); } }