0

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.

Razor Storm
  • 12,167
  • 20
  • 88
  • 148
  • The standard [java.awt.Robot](http://download.oracle.com/javase/6/docs/api/java/awt/Robot.html) can do some of that stuff. –  Aug 22 '11 at 23:01
  • Shopping and recommendation questions are not considered on-topic. – Kev Aug 22 '11 at 23:18

2 Answers2

4

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.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
1

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

Community
  • 1
  • 1
zhongshu
  • 7,748
  • 8
  • 41
  • 54