<commit_before>package OSXKeyboard

/*
#cgo LDFLAGS: -framework ApplicationServices -framework Carbon
extern int listen();
*/
import "C"

import (
  "errors"
  "fmt"
)

var (
  // flag variable to check whether the c code was already called
  isListening = false
  // Channels list of all the channels where the letters will be streamed
  Channels = make(map[int]*chan string)
)

// Listen start listening the keyboard events
func Listen() error {

  // start the c code listeners to call the go function hook
  if isListening == false {

    ok := C.listen()

    if ok == 1 {
      return errors.New("It was not possible to listen the global keyboard events, make sure to have the root permissions enabled")
    }
    // change the flag to true to avoid entering this condition again
    isListening = true
  }

  return nil

}

// AddChannel add a channel to the Channels list
func AddChannel(ch *chan string) {
  // add che channel to the list
  Channels[len(Channels)] = ch
}

// GoKeypressCallback hook function called in the c code
//export GoKeypressCallback
func GoKeypressCallback(key *C.char) {

  letter := C.GoString(key)

  fmt.Println(letter)

  for i := 0; i < len(Channels); i++ {
    *Channels[i] <- string(letter)
  }

}
<commit_msg>removed: debug fmt<commit_after>package OSXKeyboard

/*
#cgo LDFLAGS: -framework ApplicationServices -framework Carbon
extern int listen();
*/
import "C"

import (
  "errors"
)

var (
  // flag variable to check whether the c code was already called
  isListening = false
  // Channels list of all the channels where the letters will be streamed
  Channels = make(map[int]*chan string)
)

// Listen start listening the keyboard events
func Listen() error {

  // start the c code listeners to call the go function hook
  if isListening == false {

    ok := C.listen()

    if ok == 1 {
      return errors.New("It was not possible to listen the global keyboard events, make sure to have the root permissions enabled")
    }
    // change the flag to true to avoid entering this condition again
    isListening = true
  }

  return nil

}

// AddChannel add a channel to the Channels list
func AddChannel(ch *chan string) {
  // add che channel to the list
  Channels[len(Channels)] = ch
}

// GoKeypressCallback hook function called in the c code
//export GoKeypressCallback
func GoKeypressCallback(key *C.char) {

  letter := C.GoString(key)

  for i := 0; i < len(Channels); i++ {
    *Channels[i] <- string(letter)
  }

}

{'fraction_non_alphanumeric': 0.09120258272800645, 'fraction_numerical': 0.0016142050040355124, 'mean_word_length': 3.2667814113597244, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6385675', 'n_tokens_mistral': 751, 'n_tokens_neox': 728, 'n_words': 302}