                                                :columns 80
                                                ))
                        "span"]])]
+
+    (defn stop-listening [active-chan comm-chan log-widget te-name]
+      (log log-widget "Stopping listening\n")
+      (go
+       (if (<! active-chan)
+         (do
+           (if-let [ c (<! comm-chan)]
+             (do
+               (log log-widget "closed keys channel from comm-chanel\n")
+               (close! c)
+               (>! active-chan false)
+               )
+             )
+           (log log-widget (str "SENDING " (text te-name) "\n"))
+           )
+         (log log-widget "read false from active chan")
+         ))
+      )
+    (defn start-listening [active-chan comm-chan log-widget te-name]
+      (log log-widget "Starting listening\n")
+      (go
+       (>! comm-chan (chan 1))
+       (>! active-chan true)
+       (loop []
+         (let [keys-chan (<! comm-chan)]
+           (>! comm-chan keys-chan)
+           (let [[v ch] (alts! [keys-chan (timeout 1000)])]
+             (if (not (blank? v))
+               (recur)
+               (do
+                 (log log-widget "timeout reached\n")
+                 (stop-listening active-chan comm-chan log-widget te-name))
+               ))
+           ))))
+
+    ;; It is important in this scheme to return value to the channel as soon as it had been read:
+    ;; so that others interested can read back
+
     (let [te-name (select form [:#username])
           lb-log (select form [:#log])
-          c (chan)]
+          active-chan (chan 1)
+          comm-chan (chan 1)]
       (listen te-name
+              :focus-gained (fn [e]
+                              (put! active-chan false)
+                              )
+
               :document (fn [e]
-                          (put! c (text te-name)))
-              :focus-gained (fn [e]
-                             (go-loop []
-                                      (let [[v ch] (alts! [c (timeout 1000)])]
-                                        (if (not= v "stop")
-                                          (do
-                                            (if (not (blank? v))
-                                              (log lb-log (str "read " v ", waiting continues...\n"))
-                                              (log lb-log (str "timeout reached, getting avatar for " (text te-name) "\n")))
-                                            (recur))
-                                          (log lb-log "exiting loop.")))))
+                          (go
+                           (if (<! active-chan)
+                             (do
+                               (>! active-chan true)
+                               (log lb-log "in active mode, sending keypress\n")
+                               (let [keys-chan (<! comm-chan)]
+                                 (>! comm-chan keys-chan)
+                                 (>! keys-chan "1")
+                                 ))
+                             (do
+                               (log lb-log "in not-active mode, initiating listening\n")
+                               (start-listening active-chan comm-chan lb-log te-name))
+                             ))
+                          )
               :focus-lost (fn [e]
-                            (log lb-log "sending stop\n")
-                            (put! c "stop")))
+                            (log lb-log "focus lost, stopping\n")
+                            (stop-listening active-chan comm-chan lb-log te-name)
+                            )
+              )
 
       )
-      form
-      )
-    )
-;; (config! f :content (build-content))
-;; (def f (make-frame (build-content)))
-;; (show! f)
+    form)
+  )
 
 (defn build-posts-tab []
   (label "Posts"))

  (:use [seesaw.mig])
  (:use [seesaw.widgets.log-window])
  (:require [clojure.string :refer [blank?]])
  (:require [clojure.core.async :refer [chan alts!! timeout thread]])
  )
; (require '[clojure.core.async :refer [chan alts!! alts! timeout thread put! go-loop]])
; (require '[clojure.string :refer [blank?]])

(defn build-avatars-tab []
  (let [bg-stamp-pos (button-group)

   :content (label "hello") ;; TODO replace label => (build-content)
   ))

(def f (make-frame (build-content)))
(show! f)
(config! f :content (build-content))


(defn -main [& args]
  (invoke-later
   (->
