# Slipstreaming the 'comment entry' process

**URL:** <https://discuss.epiforge.com/t/slipstreaming-the-comment-entry-process/34>\
**Category:** Grindstone 4\
**Created:** [March 1, 2020, 11:11pm UTC](https://discuss.epiforge.com/t/slipstreaming-the-comment-entry-process/34 "2020-03-01T23:11:31Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![daniel.henry](https://yyz1.discourse-cdn.com/flex031/user_avatar/discuss.epiforge.com/daniel.henry/32/28_2.png) [@daniel.henry](https://discuss.epiforge.com/u/daniel.henry)\
**Post date:** [March 2, 2020, 6:10am UTC](https://discuss.epiforge.com/t/slipstreaming-the-comment-entry-process/34/6 "2020-03-02T06:10:01Z")

</div>

I had a good time implementing your first request tonight.

Added ModifiedAcceptsReturnBehavior.cs:

```auto
using System.Linq;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
using System.Windows.Controls;

namespace Quantum.Client.Windows
{
    public static class ModifiedAcceptsReturnBehavior
    {
        public static readonly DependencyProperty IsEnabledProperty =
            DependencyProperty.RegisterAttached("IsEnabled", typeof(bool), typeof(ModifiedAcceptsReturnBehavior), new PropertyMetadata(false, OnIsEnabledChanged));

        public static bool GetIsEnabled(DependencyObject obj) => (bool)obj.GetValue(IsEnabledProperty);

        static void OnIsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (e.Property == IsEnabledProperty && sender is TextBox textBox && e.NewValue is bool newValue)
            {
                if (newValue)
                    textBox.PreviewKeyDown += PreviewKeyDown;
                else
                    textBox.PreviewKeyDown -= PreviewKeyDown;
            }
        }

        private static void PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if ((App.Configuration?.EnterConfirmsDialogsInMultilineTextboxes ?? true) &&
                sender is TextBox textBox &&
                textBox.AcceptsReturn &&
                e.Key == System.Windows.Input.Key.Enter &&
                !System.Windows.Input.Keyboard.IsKeyDown(System.Windows.Input.Key.LeftCtrl) &&
                !System.Windows.Input.Keyboard.IsKeyDown(System.Windows.Input.Key.RightCtrl) &&
                !System.Windows.Input.Keyboard.IsKeyDown(System.Windows.Input.Key.LeftAlt) &&
                !System.Windows.Input.Keyboard.IsKeyDown(System.Windows.Input.Key.RightAlt) &&
                !System.Windows.Input.Keyboard.IsKeyDown(System.Windows.Input.Key.LeftShift) &&
                !System.Windows.Input.Keyboard.IsKeyDown(System.Windows.Input.Key.RightShift) &&
                Window.GetWindow(textBox).FindVisualChildren<Button>().FirstOrDefault(b => b.IsDefault) is Button defaultButton &&
                new ButtonAutomationPeer(defaultButton).GetPattern(PatternInterface.Invoke) is IInvokeProvider defaultButtonInvokeProvider)
            {
                defaultButtonInvokeProvider.Invoke();
                e.Handled = true;
            }
        }

        public static void SetIsEnabled(DependencyObject obj, bool value) => obj.SetValue(IsEnabledProperty, value);
    }
}

```

Invoked the new guy in the default text box style:

```auto
<Style x:Key="AppTextBoxStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextBoxStyle}">
    <!-- other stuff I didn't paste in here -->
    <Setter Property="local:ModifiedAcceptsReturnBehavior.IsEnabled" Value="True" />
</Style>

```

That’s right, bruh. Took less than fifteen minutes to implement. Still got it.

[https://media.tenor.com/eFklYI7QfRoAAAAd/muscles-flex.gif(image larger than 4 MB)](https://media.tenor.com/eFklYI7QfRoAAAAd/muscles-flex.gif)

If you want to see it for yourself, check out [the topic for the upcoming preview release](https://discuss.epiforge.com/t/2020-02-12-preview-release-notes/20) for instructions.

> [@lachiewatson](#):
>
> Another ‘nice to have’ would be an option for a default selection when returning to an unattended computer. ‘Continue timing on what I left off’ or what not, and have the ‘OK’ button pre-selected, so that a simple strike of the Enter key will get things back on track where they were previously.

Ahh, let’s see how hard _that_ would be…

---

_[View the full topic](https://discuss.epiforge.com/t/slipstreaming-the-comment-entry-process/34)._
