-2

The insert key on the keyboard (ins) makes it possible to override text. Is it possible to activate that key so the insert key function is on when my application starts? I'm working in C# windows forms

I tried:

      var key = Key.Insert;                    // Key to send
  var target = Keyboard.FocusedElement;    // Target element
  var routedEvent = Keyboard.KeyDownEvent; // Event to send

  target.RaiseEvent(
    new KeyEventArgs(
      Keyboard.PrimaryDevice,
      PresentationSource.FromVisual(target),
      0,
      key)
    { RoutedEvent=routedEvent }
  );

and it works only on the first selected masked textbox

System.Windows.Forms.SendKeys.Send("{INSERT}");
Ewout
  • 188
  • 1
  • 5
  • 13
  • You have to be more specific. What are you trying to achieve? – Emil Lundin Apr 09 '15 at 14:47
  • I want to override text in a masked text box when typing in it so when I press the insert key on the keyboard it will override it but can I do this too in code so I dont have to press it ? – Ewout Apr 09 '15 at 14:48
  • 1
    http://stackoverflow.com/questions/1645815/how-can-i-programmatically-generate-keypress-events-in-c – Emil Lundin Apr 09 '15 at 14:51
  • possible duplicate of [How to Set WinForms Textbox to overwrite mode](http://stackoverflow.com/questions/1428047/how-to-set-winforms-textbox-to-overwrite-mode) – James Apr 10 '15 at 08:50

1 Answers1

2

Insert/Overwrite is a temporary state, dependant on the control receiving the input. Note that there's no indicator for it on a keyboard.

Go open Visual studio, Notepad and perhaps Notepad++ or another text editor which supports insert. hit insert in VS and you can switch between insert/overwrite. focus on the other text editor and you have to hit insert again. Focus on notepad and insert does nothing, it's not supported.

You'll have to run the code to change the write mode to overwrite when the target receives focus. Or you can implement you're own textbox variant which always overwrites.

James
  • 9,774
  • 5
  • 34
  • 58