Example #1
0
/*
RegisterKey allows entities to receive key presses by registering the functions
to execute when a key is either pressed or released.
*/
func (c *Controller) RegisterKey(key string, onPress, onRelease func()) error {
	// check if key is valid
	code := sdl.GetKeyFromName(key)
	// FIXME determine how we can check for illegal values
	log.Println("DEBUG: illegal code? :", code)
	// make keyReceive struct
	receive := &keyReceive{
		lastState: false,
		onPress:   onPress,
		onRelease: onRelease}
	_, exists := c.keyreceivers[key]
	if !exists {
		// if new key --> create array with first chan
		c.keyreceivers[key] = []*keyReceive{receive}
	} else {
		// if other entities already registered -> append chan
		c.keyreceivers[key] = append(c.keyreceivers[key], receive)
	}
	return nil
}
Example #2
0
File: keys.go Project: eandre/drip
func FromName(name string) Key {
	code := sdl.GetKeyFromName(name)
	return Key(code)
}