0

I want to make an application that will replace a certain string when I type in any textfield of any application (online textboxes, notepad, word, email, etc..)

For example if I'm writing in notepad++ and I type [for] and press space or enter I want my C# application to work in background, access the field and replace that string with a predefined string in my C# code.

The result would for example be:

for($i = 0; $i < X; $i++)
{
   // ....
}

For example if I'm writing a word document and I input [FIRSTPAGE] I would want that to be replaced with a random string I setup early.

Later on I will setup an app that will let me change these on the fly.

I tried searching google but I found no information on anything similar. I just need to find a way to replace a string in any textfield.

Hope this makes sense. Thanks for your help.

bbrez1
  • 135
  • 2
  • 10
  • Tried the documentation? STring.Replace, Regex - not exactly stuff not directly in there. Naturally noone will deliver you a complete solution. – TomTom Jun 06 '14 at 13:04
  • 1
    @TomTom Those aren't really relevant. – Rawling Jun 06 '14 at 13:05
  • you can probably find some spellcheck software and add values to the lookup database to "autocorrect" to the strings you are looking for – Kevin Cook Jun 06 '14 at 13:06
  • OP, take a look [here](http://stackoverflow.com/questions/10383569/monitoring-keyboard-activity-in-c-sharp-while-my-application-is-in-the-backgroun) to get you started. Not flagging as duplicate as it only answers half your question (mechanics of hooking, not how to monitor over time & replace). – Rawling Jun 06 '14 at 13:07
  • 1
    @Rawling They are totally relevant given the description of the problem you gave. Obviously you have a problem asking the right question, because "rplace string in application" is a little thing people do as training in week 2 of playing with C#, latest. And if you want something a lot more complex then - no, not many people do text editors. – TomTom Jun 06 '14 at 13:07
  • Take a look at AutoHotKey. I think you can compile its scripts into standalone applications. – Matthew Strawbridge Jun 06 '14 at 13:08
  • @TomTom I'm not the asker, genius. Wanting to monitor keypresses and replace them in realtime is probably not going to be achieved through `string` or `Regex` `.Replace` methods. – Rawling Jun 06 '14 at 13:15
  • 2
    @Rawling is correct. And I'm not even near asking for a complete solution. I'm just asking for the most important part: a way to monitor whats written in another application and replace that with another string. – bbrez1 Jun 06 '14 at 13:22

2 Answers2

2

Create a global keyboard hook, C# : Keyboard Hook shows how you can do it.

Once hook is created monitor handle the keylog for typed word. Once the typed word is found use SendKeys to send keystrokes virtually.

Community
  • 1
  • 1
Parimal Raj
  • 20,189
  • 9
  • 73
  • 110
0

There's a really cool library called Scintilla.NET - http://scintillanet.codeplex.com/

It's usually used for building your own code editor with syntax highlighting support. But it has the auto-suggest feature you are after, i.e:

enter image description here

Latheesan
  • 23,247
  • 32
  • 107
  • 201