Avatar of gawacha1
gawacha1
Flag for India asked on

How to access textarea of MS Notepad using vb.net?

How to access text-area of MS Notepad using vb.net?
Visual Basic.NET

Avatar of undefined
Last Comment
gawacha1

8/22/2022 - Mon
SOLUTION
Rainverse

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Mike Tomlinson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
gawacha1

ASKER
Dear Idle_Mind

here we're sending the text from Form1.Textbox1 to notepad.
I want to do it from KeyDown, say
rt=Richtextbox1
rt.SelectionStart = rt.SelectionStart - 3
                        rt.SelectionLength = 3

rt.SelectedText = ""
rt.SelectedText = "abc" ' abc are Unicode characters

I understand it is possible to send chars to notepad thro SendInput only, but is there some way to access textarea of notepad/ winword directly

Regards
Mike Tomlinson

SendInput() simply injects keystrokes into the stream.  Whatever application happens to be in the foreground will get them and process them as normal.  Thus you can't target the textarea of notepad/winword directly with SendInput().  To target them directly requires an approach like I've outlined above.
gawacha1

ASKER
Dear Idle_Mind

Sorry to have used name notepad etc. what i want is target foreground application directly without using SendInput.
The keystroke has to go directly to  window after character replacement through my application. In your code i write in my application and then press button to send it to foreground window. Also your code is not working with Unicode. Is this possible.

Regards
Your help has saved me hundreds of hours of internet surfing.
fblack61
gawacha1

ASKER
Please see
https://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_28086066.html
if this can work, i do not need any alternate solution
Mike Tomlinson

Hmmm....the advantage of Sendkeys() is that it targets the active foreground window without requiring knowledge of what that application is, or requiring any window handles.

Given any foreground window, though, it's impossible to know whether keystrokes should be sent directly to the main window handle or if they need to be sent directly to a child window (like with Notepad).  Thus with SendMessage() and sending keys directly to a window, that approach should be used for specific situations and not a general approach for all applications.
gawacha1

ASKER
my question remains - Send any-which-way to foreground window by a single key-press 'sequence of 3 Unicode characters'

please give sample code

regards
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.