title: Capture key stroke from separate process in Java
body: <p>I want this to happen:</p>
  
  <ol>
  <li>Start my java program  </li>
  <li>My java program launches notepad.exe  </li>
  <li>If I type a letter in notepad my java program should react and print out the letter</li>
  </ol>
  
  <p>In short: Is it possible to make a key event listener for another process? The java program won't have focus.</p>
  
  <p>If it's impossible I want to be able to change focus between my Java swing window and the notepad process. For example:</p>
  
  <p>A) My java program has focus (small swing window), I type the letter "A"<br>
  B) Notepad is given focus quickly and the letter A is typed there (for example using the Robot class)<br>
  C) My java program gets focus again</p>
  
  <hr>
  
  <p>Quoting the answer given in <a href="https://stackoverflow.com/questions/10340024/creating-a-keyboard-hook-for-a-java-program-that-sits-in-the-system-tray/">Creating a keyboard hook for a Java program that sits in the System Tray</a></p>
  
  <p>so , creating a keyboard hook isn't as easy as it looks , java doesn't provide a direct way to interact with the system events for purposes of security ; as it might lead to serious problems concerning the JVM , system's memory and the portability of Java Framework..</p>
  
  <p>you have 4 ways to make global keyboard hooks :</p>
  
  <ol>
  <li>Learn JNI / JNA, and I prefer JNA since its much easier than JNI , in both cases you shall deal with .dll files.</li>
  <li>Use JIntellitype , which - as you said - issues some problems.</li>
  <li>the elegant solution by Sergei Biletnikov here <a href="http://biletnikov-dev.blogspot.com/2009/09/global-hotkeys-for-java-applications_25.html" rel="nofollow noreferrer">http://biletnikov-dev.blogspot.com/2009/09/global-hotkeys-for-java-applications_25.html</a></li>
  <li>ignore Java , and try Autoit V3 ( I'm not 100% sure about it , but I think you could send signals/events from Autoit to your Java app , so Autoit would just work as a bridge that catches the global key strokes)</li>
  </ol>
  
  <p>Going with number 3, which is a good tutorial. If the link has 404'd maybe the project source is still up: gigapeta.com/dl/1917618aba749a</p>