Getting keyboard/input while in other programs?

I don’t know if this is possible, but I’m making a program to save certain keyboard or mouse actions you have done on your computer and reproduce them for you, helping out with a lot of things like mundane multimedia tasks and whatnot. I’ve got the reproduction part and right now I have a fullscreen undecorated semi-transparent JFrame pop up so that you can simulate the mouse and keyboard movement you are doing, but it obviously isn’t recording the actual ones and so multistep recordings that require the program you are working in to change (like pressing a button and having a window pop up) clearly won’t work, unless you guess where things are going to happen.

So, my question is – is there any way to record mouse and keyboard input from anywhere on the computer, even while some Swing component does not have focus? Can I trick a Swing component to always thinking it has focus, and therefore it will always record everything anyway? Could I override some hasFocus() method or something?

Thanks once again, guys.

JInput can works with no windows, so yes, it will work :slight_smile:

Endolf

Ha, that’s kind of a copout, though, isn’t it? I suppose I could use that if I needed to, but are there any Swing methods anyone knows of?

well, if it’s imperative for swing to receive events you could pass your stuff you recorded from JInput (or awt listener) to them… I myself don’t know technically how, just a theory I have.

I’ve made a similar program but couldn’t find a way to do that kind of macro-recording either.

By the way, how are you doing the scripting for yours? I made the program take a kind of script that could do loops, ifs methods etc but it was pretty hit & miss - I basically invented my own useless language. I think it’d be best to use one of the scripting APIs in JDK 6 now.

Keith

PS: something I just learned recently was that toolkit has a method to set the locking state of caps, num lock etc. Don’t use Robot to do this since it doesn’t work properly.

I don’t invent my own scripting language – although I have done it before – all I do is basically have a LinkedList of conditions and actions. Condition and Action are each an interface, with one method. A Condition knows if it is true, and an Action knows how to perform itself. Essentially, if everything in the conditions list is true, everything in the actions list performs. A new Condition can also be a new action, allowing for nested ifs.

As for the scripting language, the best way I’ve found is to write a language then translate it into Java code, then use javac to compile the Java into bytecode, which will in effect run as quickly as the rest of your program. I tried to create a scripting language from the ground up and it was really god damned slow because I didn’t have the time to spend on making it very good. This is the best option if that’s what you want.