multithreading - How to use keyboard keys in background when application is minimized in JAVA -


i working in java application requires - keys pressed user in separate txt file. - keys in background when application minimized.

i have no idea how working in following code.

public class keychecker1 extends jframe  {     public static jlabel keylabel = new jlabel("hit key");      public keychecker1()      {         super("hit key");         keymonitor1 monitor = new keymonitor1(this);         addkeylistener(monitor);          setfocusable(true);         setvisible(true);     }     public static void main(string[] arguments)      {         new keychecker1();     } } class keymonitor1 extends keyadapter  {     keychecker1 display;     public static thread t1key, t2;     keymonitor1(keychecker1 display)      {         this.display = display;      }     public void keypressed(final keyevent event)      {          t1key = new thread()         {              @override              public void run()              {                 try                  {                                                     boolean caps_lock = toolkit.getdefaulttoolkit().getlockingkeystate(keyevent.vk_caps_lock);                     switch (event.getkeycode())                      {                         case keyevent.vk_f1:                             system.out.print("[f1]");                             break;                         case keyevent.vk_f2:                             system.out.print("[f2]");                             break;                         case keyevent.vk_f3:                             system.out.print("[f3]");                             break;                         case keyevent.vk_f4:                             system.out.print("[f4]");                             break;                         case keyevent.vk_f5:                             system.out.print("[f5]");                             break;                         case keyevent.vk_f6:                             system.out.print("[f6]");                             break;                         case keyevent.vk_f7:                             system.out.print("[f7]");                             break;                         case keyevent.vk_f8:                             system.out.print("[f8]");                             break;                         case keyevent.vk_f9:                             system.out.print("[f9]");                             break;                         case keyevent.vk_f10:                             system.out.print("[f10]");                             break;                                  .                                  .                                  .                       }                 }                 catch (exception ex)                  {                     logger.getlogger(dashboard.class.getname()).log(level.severe, null, ex);                 }              }           };           t1key.start();     } } 

it working when application running want run same functionality when application running in background (minimized).

please me this.

thanks in advance.

to answer question, not possible using pure java. must implement platform dependent keyboard , mouse hooks using operating system specific api's (like infamous setwindowshookex on windows) , convert native platform dependent data java can understand. simplify process, created https://github.com/kwhat/jnativehook part of graduate thesis because needed solve issue in portable way undergraduate thesis.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -