title: KeyListener and Game Thread
body: <p>i got a problem and i hope i can describe it to you guys beautifully.</p>
  
  <p>i have this game i am creating</p>
  
  <p>like all games i have this update method in a thread</p>
  
  <pre><code>update();
  </code></pre>
  
  <p>and also i have implemented a key listener;</p>
  
  <p>now heres my problem, i have a ButtonState enum:</p>
  
  <pre><code>enum ButtonState{down,up}
  </code></pre>
  
  <p>i have a KeyboardState class:</p>
  
  <pre><code>KeyBoardState{
   public ButtonState A=ButtonState.up;
  }
  </code></pre>
  
  <p>i have a Keyboard class that has a static KeyboardState</p>
  
  <pre><code>KeyBoard{
      public static KeyboardState state=new KeyboardState();
  }
  </code></pre>
  
  <p>in my KeyListener its like this:</p>
  
  <pre><code>keyPressed(KeyEvent e){
  if(e.getKeyCode()==KeyEvent.VK_A)KeyBoard.getKeyBoardState().W=ButtonState.down;
  }
  
  keyReleased(KeyEvent e){
  if(e.getKeyCode()==KeyEvent.VK_A)KeyBoard.getKeyBoardState().W=ButtonState.up;
  }
  </code></pre>
  
  <p>now in my update code its like this</p>
  
  <pre><code>KeyBoardState current=new KeyBoardState();
  KeyBoardState old=new KeyboardState();
  
  update(){
  
      current=Keyboard.state;
      //here both current and old become buttonstate.down when pressed and vice versa
      if(current.a==ButtonState.down &amp;&amp; old.a==ButtonState.up){
       //do
      }
      old = current;
  }
  </code></pre>
  
  <p>my problem is this, whenever i press A, both current.a and old.a becomes  ButtonState.down and same when i release it. so the code never goes to //do.</p>
  
  <p>can i make it that KeyListener is in the same thread as the game? if so how?</p>