Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I just now want a very sample code. Suppose -
If I open my program and type anywhere - AT it will replace full string and type @ and OOK it will type $ and etc etc.

if I type these charter middle of a word then also replace.Suppose

I am writting on Notepad ...

I type normally - CAT
After opening my program AND then type CAT - C@ (Replace AT to @)

Normally Type - BOOK
After opening my program and then if I type book -B$ (replace OOK to $)

I hope everyone understand me clearly what I am really looking for.

Thanks in advanced
Posted
Comments
joshrduncan2012 15-Nov-13 9:33am    
What have you tried so far to accomplish this? Where are you stuck?
expert-programmer 15-Nov-13 9:47am    
Thanks for your comment first.
The truth is I didn't try...
because I don't know how to start.
when I don't know how to start then how can I start.

I need this very very very much.
have you any solution about it?
GuyThiebaut 15-Nov-13 9:57am    
A bit of advice from a seasoned developer - if you don't know where to start:

1 - break your problem down into manageable chunks.
2 - search on google for clues on how to implement these manageable chunks.
3 - start coding.

Even developers like me who have 20+ years of programming experience get stuck sometimes, don't let getting stuck be something that defines you as a programmer ;)
expert-programmer 15-Nov-13 10:17am    
Thanks a lot for your advice.

about point 2 - I searched a lot on googLe.read all related topic. But these was not helpful what I am looking for.
I found. sample for replace text in rft,textbox etc.
but I need to replace anywhere while I am typing.

about point 3- how to start?

you have +20 years experience in programming but my age is 17. and I have not 20 month experience too.
but I made my all programs to take codeproject helps.all success programs.
Sergey Alexandrovich Kryukov 15-Nov-13 10:29am    
Quite possible, but I strongly recommend not to do it. It can strongly confuse the user, to say the least. Right approach is to sanitize the string or validate or show validation problem when a string is using. In contrast to that, just filtering out some characters is perfectly acceptable.
—SA

expert-programmers do use Google always. Why didn't you? :|

Got this one[^] from Google
 
Share this answer
 
Comments
expert-programmer 15-Nov-13 10:21am    
Thank you a lot for spend some time on google to find a solution.
But I an very afraid to tell you - I need to replace string anywhere. Such while typing on notepad,ms word etc. Not a specific location. such winform textbox.
I hope you understand.
Sergey Alexandrovich Kryukov 15-Nov-13 13:04pm    
I tried hard to pull this "anywhere" from you, but only now you explained it properly. Now, I advise not to do it even strongly than in first place. Really, really bad idea. And it just don't worth the effort. Implementing your own editor doing what you want (and then you can past results anywhere) would way easier and more useful.

But I have a very similar idea which could be a bit more reasonably considered. Say, it could be a specialized input method (much like virtual keyboard) which would type where you want. But also, too much work for a very questionable goal.

—SA
expert-programmer 15-Nov-13 13:22pm    
Now I say - You catch the right point !
Actually I am working with input method.
I am making a word processing software for my own language and there is a lot combination keys.

If possible give me both. Or anyone. I wanna see code. Then I hope I can solve my problem.

Thanks in advanced
Sergey Alexandrovich Kryukov 15-Nov-13 14:17pm    
I don't have such code, just know how to make it. There is one more possibility, closer to input method: Microsoft Layout Creator. Did you try it? I actually use my own layout created by it, it is officially installed in the system...
I'll show you what I have, if you are interested...
—SA
expert-programmer 16-Nov-13 1:02am    
You know how to make it! that's great! sounds so good.
I need it very much. My program 70% is this. Actually this can complete my program 100%.

However About MKLC I tried it a long ago.
Does it supports sequences?
I means if I am typing CAT will it able to make it C@?
if yes then I go with it. I think this maybe can't do with MKLC.

I mostly need to string replace in sequence.
Because there are a lot combination key on my language.
I hope you understand clearly.

Thanks a lot. Thanks in advanced
First thing you need to realize is: you either need to give up the idea of replacement of anything from the input control, or otherwise give up the idea of affecting all possible applications. Just forget one or another. Say, you type OOK, but actually, you type O, then another O, then K, and then want to replace all three with $. Too late. You can type something processing some key strokes, but it you have already types three characters, they are already there. You cannot expect that you input anything in a window which can be accesses with WM_SETTEXT/WM_GETTEXT. You cannot expect that it is a Windows window object at all. Whole WPF application does not have any except main window. And you cannot simulate backspace: you are talking about any arbitrary application, but such application can be totally custom and simply ignore some key presses or interpret them in a different way.

So, the scenario you described in impossible in principle. All you can count of it your own application. It could collect some information on key strokes and not output them. It, say could collect "OO", but output it only when you add "K". If you add some other character, it will output all three at once. Needless to say, it would be quite confusing to the users.

The second thing you would need to forget about is using pure .NET. Whatever you do, you would need to use at least some native (unmanaged) software development, which you can combine with .NET using P/Invoke and/or C++/CLI.

You apparently need to invent something else. First thing which comes to mind is Windows Input Method Editors (IME). But I don't know your set of OS you want to support. Anyway, to get an idea, please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/hh848069%28v=vs.85%29.aspx[^],
http://code.msdn.microsoft.com/windowsdesktop/Input-Method-Editor-IME-b1610980[^],
http://msdn.microsoft.com/en-us/library/windows/apps/hh967425.aspx[^],
find some more: http://bit.ly/1azes7b[^].

You can also develop some custom application which you should start and stop, processing raw system-wide keyboard events system-wide, and you can develop a way to enable/disable this processing.

First part of Windows API you would need is Windows Hooks. Please see my past answers for further detail:
Creating global shortcuts.[^],
How to set a window hook in other application?[^],
How the Keyboard Hook works and how it is being implemented[^].

Pay attention for my explanations related to collaboration between .NET and native code, P/Invoke and C++/CLI. This is what you always would need. For the output part of the solution, too. To simulate any kind of keyboard input, you would need to use raw Windows method SendInput:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^],
in .NET via P/Invoke: http://www.pinvoke.net/default.aspx/user32.sendinput[^].

Overall, I would strongly discourage you to implement any of your idea. Perhaps I could give you a better advice if I knew your ultimate goal.

—SA
 
Share this answer
 
Comments
expert-programmer 18-Nov-13 2:35am    
thank you a lot for your a lot help.you spend a lot of your valuable time for me.thanks again for it.

i dont know i can do something with it.
ok see what can i do with these links.

thanks
Sergey Alexandrovich Kryukov 18-Nov-13 2:58am    
My pleasure.
Well, read on the subject first, and later we can discuss it...
—SA
expert-programmer 18-Nov-13 5:02am    
Hello SA,
I even really know the language to thank you. You reply my all questions with best answer.

i think i got a possibility on here - http://www.pinvoke.net/default.aspx/user32.sendinput

but how to use this code for me?
could you give me some instruction?

thanks
Sergey Alexandrovich Kryukov 18-Nov-13 12:21pm    
You are very welcome.
You just need to try using the code provided by pInvoke.NET, see the link above, copy all the declaration from this page to your code. I did it; and it worked out correctly, immediately. You just fill in the structures used as the parameters of the call. Mind you, this is a very low-level function, which makes it universally applicable. Calling it let you act in exact some way the hardware drivers do, but it also can be used in application-level code, not only kernel-mode. Are you getting the idea?

Eventually, please don't forget to accept the answer formally. However, in all cases your follow-up questions will be welcome.
—SA
expert-programmer 18-Nov-13 13:09pm    
I am very afraid to say - actually i dont understand anything.

=>I did it; and it worked out correctly,
immediately...

Sounds too goods...I am toooo much happy...feeling now.

=> You just fill in the structures used
as the parameters of the call..

I maybe already told you i am only 17 and begginer level.
the truth is i dont understand these hard codes currently.

You did it and if you dont get mind could you pls upload the project to net and give me the link ?
it will be best for me....

a long time tension and problem gone....
ahh i am too happy now.my dreamy project become true for you. thanks...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900