<commit_before>package input

import (
	"github.com/go-gl/glfw/v3.1/glfw"
)

var listenerList = map[int]*listener{}

type listener struct {
	callback func(event int)
}

// AddListener creates a new key listener, only the last listener for a button will be honored
func AddListener(key int, callback func(event int)) {
	listenerList[key] = &listener{callback}
}

// AttachInputCallbacksToWindow will enable the input callbacks on specified window
func AttachInputCallbacksToWindow(window *glfw.Window) {
	window.SetKeyCallback(callback)
}

var callback = func(window *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	if li, found := listenerList[int(key)]; found {
		li.callback(int(action))
	}
}<commit_msg>add example for input listener<commit_after>package input

import (
	"github.com/go-gl/glfw/v3.1/glfw"
)

var listenerList = map[int]*listener{}

type listener struct {
	callback func(event int)
}

// AddListener creates a new key listener, only the last listener for a button will be honored
//	input.AddListener(input.KeyEscape, func(event int) {
//		if event == input.Release {
//			fmt.Println("Escape button released!")
//		}
//	})
func AddListener(key int, callback func(event int)) {
	listenerList[key] = &listener{callback}
}

// AttachInputCallbacksToWindow will enable the input callbacks on specified window
func AttachInputCallbacksToWindow(window *glfw.Window) {
	window.SetKeyCallback(callback)
}

var callback = func(window *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	if li, found := listenerList[int(key)]; found {
		li.callback(int(action))
	}
}
{'fraction_non_alphanumeric': 0.11508176862507571, 'fraction_numerical': 0.0024227740763173833, 'mean_word_length': 4.9855072463768115, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6836119', 'n_tokens_mistral': 541, 'n_tokens_neox': 534, 'n_words': 149}