Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
4.00/5 (1 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

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.

[Update]
~~~~~~~~~~~

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.
 
Share this answer
 
v4
Comments
Sergey Alexandrovich Kryukov 21-Feb-11 20:57pm    
My 5. This is working, only you need to use caution.
--SA
Sergey Alexandrovich Kryukov 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.
--SA
Nish Nishant 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.
Sergey Alexandrovich Kryukov 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.
--SA
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 http://msdn.microsoft.com/en-us/library/ms646310(v=vs.85).aspx[^]. 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.)

—SA
 
Share this answer
 
v2
Comments
Nish Nishant 21-Feb-11 21:12pm    
Voted 5 for the extra info.
Sergey Alexandrovich Kryukov 21-Feb-11 21:18pm    
Thank you, Nishant.
--SA
klixxx 21-Feb-11 22:12pm    
Thank you very much, this was what I was looking for.
Sergey Alexandrovich Kryukov 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.
--SA
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.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 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".
--SA

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