Is there a way to dispatch programmatically constructed KeyEvents so that they are indistinguishable by my application from those arising from physical key presses? I have tried looking at How does Java Dispatch KeyEvents as well as the KeyboardFocusManager and KeyEventDispatcher APIs, but I haven't been able to figure it out, nor is it even clear that these were the correct places to be looking for an answer. Thanks for any help.
Asked
Active
Viewed 106 times
1
-
please whats goal ??? only to protect your GUI against KeyEvents came from physical KeyBoard, nothing else – mKorbel Jan 14 '14 at 20:15
-
4The simplest solution would be to use Robot...try taking a look at [this example](http://stackoverflow.com/questions/14572270/how-can-i-perfectly-simulate-keyevents/14615814#14615814) which uses both a Robot and event dispatching techniques... – MadProgrammer Jan 14 '14 at 20:16
-
1@MadProgrammer please how this help, maybe I'm miss something, because from AWTEventLIstener is possible/can to consume() – mKorbel Jan 14 '14 at 20:18
-
@mkorbel Yes, it's possible for an event to consumed, nothing you can really do about that, but from the perspective of the key management, the event dispatching process deals only with AWT events, it doesn't care/know how they generated – MadProgrammer Jan 14 '14 at 20:21
-
@mKorbel my goal is to build a virtual keyboard from JButtons, so that clicking a button would dispatch a KeyEvent as if the corresponding keyboard key had been pressed. – alpacahaircut Jan 14 '14 at 20:49
-
Thanks @MadProgrammer. Robots appear to be doing the trick. – alpacahaircut Jan 14 '14 at 21:05
-
@plattnum here is a few good virtual keyboards, part of them uses KeyBindings, (without KeyBindings) then every events are only from mouse events and ENTER/TAB key from keyboard (KeyBindings) – mKorbel Jan 14 '14 at 21:13