private void Client_PreviewKeyUp(object sender, KeyEventArgs e) { Key key = (e.Key == Key.System ? e.SystemKey : e.Key); switch (key) { case Key.LeftShift: case Key.RightShift: modifier = modifier & ~modifier_t.shift; shiftRect.Fill = new SolidColorBrush(Colors.White); e.Handled = true; break; case Key.LeftCtrl: case Key.RightCtrl: modifier = modifier & ~modifier_t.ctrl; ctrlRect.Fill = new SolidColorBrush(Colors.White); e.Handled = true; break; case Key.LeftAlt: case Key.RightAlt: modifier = modifier & ~modifier_t.alt; altRect.Fill = new SolidColorBrush(Colors.White); e.Handled = true; break; default: break; } }
private void HorizontalToggleSwitch_Checked(object sender, RoutedEventArgs e) { shiftRect.Fill = new SolidColorBrush(Colors.White); ctrlRect.Fill = new SolidColorBrush(Colors.White); altRect.Fill = new SolidColorBrush(Colors.White); modifier = modifier_t.none; this.PreviewKeyDown += Client_PreviewKeyDown; this.PreviewKeyUp += Client_PreviewKeyUp; capturing = true; }
private void Client_PreviewKeyDown(object sender, KeyEventArgs e) { Key key = (e.Key == Key.System ? e.SystemKey : e.Key); switch (key) { case Key.LeftShift: case Key.RightShift: modifier = modifier | modifier_t.shift; shiftRect.Fill = new SolidColorBrush(Colors.DeepSkyBlue); e.Handled = true; break; case Key.LeftCtrl: case Key.RightCtrl: modifier = modifier | modifier_t.ctrl; ctrlRect.Fill = new SolidColorBrush(Colors.DeepSkyBlue); e.Handled = true; break; case Key.LeftAlt: case Key.RightAlt: modifier = modifier | modifier_t.alt; altRect.Fill = new SolidColorBrush(Colors.DeepSkyBlue); e.Handled = true; break; default: break; } if (!e.Handled) { int convertedKey = KeyInterop.VirtualKeyFromKey(key); byte[] buffer = new byte[1 + sizeof(int)]; buffer[0] = (byte)modifier; BitConverter.GetBytes(IPAddress.HostToNetworkOrder(convertedKey)).CopyTo(buffer, 1); Stream.BeginWrite(buffer, 0, 1 + sizeof(int), new AsyncCallback(SendToServer), Stream); e.Handled = true; } }
public KeyData(modifier_t m, int k) { modifier = m; key = k; }