protected void Inject(string sWhat)
{
if (number_hit_handler != null)
{
number_hit_handler(Convert.ToInt32(sWhat));
return;
}
if (target_window != null)
{
//target_window.ControlToInjectInto.Focus();
//Microsoft.Surface.Presentation.Controls.SurfaceTextBox txtTarget = TargetWindow.ControlToInjectInto as Microsoft.Surface.Presentation.Controls.SurfaceTextBox;
TextBox txtTarget = target_window.ControlToInjectInto as TextBox;
if (txtTarget != null)
{
//txtTarget.Text.Insert(txtTarget.SelectionStart, sWhat);
txtTarget.InsertText(sWhat);
}
else
{
RichTextBox richTextBox = target_window.ControlToInjectInto as RichTextBox;
if (richTextBox != null)
{
richTextBox.InsertText(sWhat);
}
else // let's hope it's an IInjectableControl
{
PasswordBox passbox = target_window.ControlToInjectInto as PasswordBox;
if (passbox != null)
{
passbox.Password += sWhat;
passbox.SelectAll();
}
else
{
//IInjectableControl targetControl = TargetWindow.ControlToInjectInto as IInjectableControl;
//if (targetControl != null)
//{
// targetControl.InsertText(sWhat);
//}
}
}
//else // if you have other text-entry controls such as a rich-text box, include them here.
//{
// FsWpfControls.FsRichTextBox.FsRichTextBox txtrTarget = TargetWindow.ControlToInjectInto as FsWpfControls.FsRichTextBox.FsRichTextBox;
// if (txtrTarget != null)
// {
// txtrTarget.InsertThis(sWhat);
// }
}
}
}