Click here to Skip to main content
13,042,630 members (80,230 online)
Rate this:
Please Sign up or sign in to vote.
See more:
How would I go about writing text to a window like notepad? I've got my program to write code to another textbox, but I was looking to get it to output text on any page given like Notepad or a website.

I just need it to simulate a person typing on any window because I'm trying to write text to an online Java applet.

Many thanks :)
Posted 21-Feb-11 12:59pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Writing to Notepad will be easy as it's an HWND based window with HWND based controls.

But I am not so sure the same will be true for a Java applet. I have no idea how Java applets render their UI. If they use regular Windows controls, then you are in luck. On the other hand, if they use non-HWND custom controls, then it's going to be way harder (or even impossible) to write to it.

So your first step is to veify how Java applets render their UI.


I checked out a few Java applets online and it seems they use normal HWND based controls. So you seem to be in luck.

You will need to use a combination of FindWindow and EnumChildWindows to get the HWND of the target textbox. Once you get that, you can use SendMessage with WM_SETTEXT to set its text.
SAKryukov 21-Feb-11 20:57pm
My 5. This is working, only you need to use caution.
SAKryukov 21-Feb-11 21:06pm
Nishant, some Java controls are HWND based but more usually they are not (light-weight controls), so it all depends on the type of application. I additionally advised to use Spy++ and API SendInput.
Nishant Sivakumar 21-Feb-11 21:11pm
Not sure of desktop Java apps, but I tried out several Java applets using Spy++ and they are all using regular controls.

Of course there may be specific Java libraries that do fully custom UI rendering.
SAKryukov 21-Feb-11 21:20pm
Really? Right, it all depends on libraries. All beans are light-weight, if I'm not mistaken. Spy++ or any research code based on API you pointed out can easily find everything which is handle-based.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

In addition to what Nishant advised, I can add that you can do research and figure out how much you can control you Java application. Use Microsoft Spy++ to spy on message flow of any window. On top of any windowed application there is always a HWND-based windows. Everything inside client area can be anything. Light-weight Java controls are dominant; and they are not based on HWND windows messages, so your chances to use them are not big.

The alternative is using P/Invoke with the Windowd API SendInput[^]. This API allows for simulation of input events on lower level as if they are triggered by a keyboard or mouse driver. This way, anything which is done via those input devices can be simulated. As on top of ever windowed application you can use HWND handle, you can use it to bring with window on top, focus its control, etc., after that you can use SendInput. (Of, course, those tricks are dirty and error prone. If all depends on your purpose.)

Nishant Sivakumar 21-Feb-11 21:12pm
Voted 5 for the extra info.
SAKryukov 21-Feb-11 21:18pm
Thank you, Nishant.
klixxx 21-Feb-11 22:12pm
Thank you very much, this was what I was looking for.
SAKryukov 21-Feb-11 22:33pm
Really? Good for you. If you want SendInput, be careful. I tested this API, it's very powerful, but you "other process's" window behavior is a delicate thing.
Thank you for accepting my answer.
Good luck, call again.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Well I tried SAKryukov's answer... But it's too difficult for me to use.

I decided to remake the little program, and I now have it so the program contains the Webbrowser itself. I recoded it in VB.NET as well. Now, as I said before, this is a web Java applet so I can't use any get html attributes to set my text values. I need it so it just enters a text string into the browser, then presses enter. Does anyone have any ideas on how to do this... and maybe make it a little easier since I'm not advanced like you guys :)

Thanks, once again

I'll ask this in the VB.NET section. Thank you all for your help.
SAKryukov 22-Feb-11 1:14am
You're not supposed to post a text like that as an Answer: will be removed; nobody receives e-mail notification. Use "Improve question" or "Add comment".

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 21 Feb 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100