title: Actor not remembering state
body: <p>I am trying to create a sample application that monitors key strokes from scala on a windows machine using the jNativeHook library.</p>
  
  <p>I have the following listener that listens for events,</p>
  
  <pre><code>object KeyListener extends org.jnativehook.keyboard.NativeKeyListener {
  
    val keyPressedActor = implicitly[ActorSystem].actorOf(Props[KeyPressedActor](), "KeyPressedActor")
  
    def nativeKeyPressed(event: NativeKeyEvent): Unit = {
      keyPressedActor ! event    
    }
   //blank override two more methods.
  }
  </code></pre>
  
  <p>The main driver app that plugs the listener,</p>
  
  <pre><code>object ConsoleApp extends App {
    try {
      GlobalScreen.registerNativeHook();
      GlobalScreen.addNativeKeyListener(KeyListener)
    } catch {
      case nativehookException: NativeHookException =&gt; System.out.println("Encountered error while Hooking to global screen" + nativehookException.fillInStackTrace())
      case ex: Exception                            =&gt; System.out.println("Miserable ! Shouldn't have happened ." + ex.fillInStackTrace())
    }
  }
  </code></pre>
  
  <p>And this is the implementation of the actor that i want to store the key strokes in some collection,</p>
  
  <pre><code>class KeyPressedActor extends Actor {
    var testQueue = new scala.collection.mutable.Queue[String]()
  
    def receive = {
      case event: NativeKeyEvent =&gt;
  
        if (event.paramString().contains("modifiers=Ctrl")) {
           testQueue.enqueue("this_is_test")        
        }
  
      case _ =&gt; System.out.println("Bummer !  You are NOT supposed to see THIS !")
    }
  }
  </code></pre>
  
  <p>Now i am seeing each time the actor enters the block where we add a string to the queue it does not remember the last element that got inserted into it.</p>
  
  <p>I cannot understand why this is happening.
  This problem is not seen if i just have a Main app that sends messages to the actor.
  I cannot put a finger on why this is happening.</p>
  
  <hr>
  
  <p>Update :</p>
  
  <p>Actually there is something else going on with the code in a section i did not copy here initially.
  So if i have this inside the <code>if</code> block of the actor ,</p>
  
  <pre><code>NativeKeyEvent.getKeyText(event.getKeyCode) match {
            case "C" =&gt;   
                          isCPressed = true
            case "V" =&gt; isVPressed = true
            case "N" =&gt; isNPressed = true
  </code></pre>
  
  <p>this behavior is observed.
  I changed this code to this ,</p>
  
  <pre><code> val keyCode = NativeKeyEvent.getKeyText(event.getKeyCode)
  
          if (keyCode.equalsIgnoreCase("c")) {
           testQueue.enqueue("this_is_test")
          }
  </code></pre>
  
  <p>I wonder if this means that the <code>match</code> statement is running on some different context/thread ??? </p>