Can I simulate a key presses with a java application to make system hear them?
Asked
Active
Viewed 658 times
0
-
Are you looking for a way to do this with an application you're writing? If that's the case, this question will likely be migrated to StackOverflow shortly. – MBraedley Feb 20 '13 at 16:18
-
no, i'd like to print them out of java application... is it possible? – Feb 20 '13 at 16:50
-
I honestly don't know what you're asking. Can you elaborate more? – MBraedley Feb 20 '13 at 18:27
-
I need that my java application robot simulate the CTRL + C of the keyboard when i press a HotKeys combination... – Feb 20 '13 at 19:35
-
Does it have to be java? Auto Hotkey and Event Ghost might be better choices. – MBraedley Feb 20 '13 at 19:42
-
You can use `java.awt.Robot` to inject key events into the system. These keys will be avaliable to what ever window/component has focus. Check out [this](http://stackoverflow.com/questions/14595483/using-java-to-send-key-combinations/14595522#14595522) and [this](http://stackoverflow.com/questions/12188076/how-to-simulate-shift-mouse-key-press-in-java/12188180#12188180) for some examples – MadProgrammer Feb 20 '13 at 22:48
2 Answers
1
You can simulate keyboard presses with Java (using the AWT Robot class) but you can listen to key events only if you have a GUI in focus (or if you interact with native C code, but that would be pretty complicated)
For global hotkeys, it would be very easy to do it using AutoHotkey instead of Java, as MBraedley suggested.

lbalazscs
- 17,474
- 7
- 42
- 50