Windows programming in Java? [closed]
What is a easy to learn framework or technique for windows-programming (calling win32 api) in Java?
I need to be able to access the windows api to do things such as send keystrokes,开发者_如何学运维 open applications, restart windows, etc.
The easiest for me has been to make small utility programs with AutoIt version 3 and then have my Java programs call these utility programs. The programs can communicate via input and output streams. If I want to delve deeper into windows, JNA is the way to go and there are lots of examples on how to use this here and at its site. JNI is another way (JNA uses JNI actually), but I find it more difficult as my C is quite rusty.
Edit:
Many folks have suggested using a Robot object, but the problem I have had with using Robot is that you can't enumerate the non-Java windows and then activate the desired window through Java alone. Also, you can't interact directly with window controls as you can with JNA and with AutoIt.
For send keystrokes, you can use java java.awt.Robot, and for open application, java.lang.ProcessBuilder is there. There API are os independent.
And for restart windows, maybe also use ProcessBuilder to call "shutdown" command, see here. Shutdown Windows with Java
精彩评论