keylistener - Listening for input without focus in Java -
keylistener - Listening for input without focus in Java -
i'm making little programme in java using robot class. programme takes on mouse. while in course of study of debugging if starts acting in way don't want it's hard quit program, since can't move mouse on terminate button in eclipse, , can't utilize hotkeys nail because mouse constant clicking in window, giving window focus instead.
what i'd hook keylistener when nail q can quit program, way know how involves making window, , window needs focus capture input. there way hear keyboard or mouse input anywhere, regardless of has focus?
this not trivial problem , java doesn't give way elegantly. can utilize solution banjollity suggested won't work time if errant mouse clicks open fullsized window open in taskbar example.
the fact is, java default gives developers little command on os. due 2 main reasons: security (as citied java documentation) , fact different operating systems handle events differently , making 1 unified model represent of these not create whole lot of sense.
so reply question, imagine want kind of behaviour programme listens keypresses globally, not in application. require access functionality offered os of choice, , access in java going need through java native interface (jni) layer.
so want is:
implement programme in c hear global keypresses on os, if os windows documentation on windows hooks docuemented microsoft , msdn on web , other places. if os linux or mac os x need hear global keypresses using x11 development libraries. can done on ubunutu linux distro according howto wrote @ http://ubuntuforums.org/showthread.php?t=864566
hook c code java code through jni. step easier step. follow procedure utilize in tutorial @ http://ubuntuforums.org/showthread.php?t=864566 under both windows , linux procedure hooking c code java code identical on both oses.
the of import thing remember much easier jni code working if first code , debug c/c++ code , create sure working. integrating java easy.
java keylistener
Comments
Post a Comment