-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathkeys.go
40 lines (31 loc) · 776 Bytes
/
keys.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2015 Claudemiro Alves Feitosa Neto. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
const (
keyUp = 38
keyDown = 40
)
// Keys help to know which keya are pressed
type Keys struct {
Pressed map[int]bool
}
// NewKeys create a new Key
func NewKeys() Keys {
keys := Keys{}
keys.Pressed = make(map[int]bool)
return keys
}
// IsDown verify if the given key is pressed
func (k *Keys) IsDown(key int) bool {
stat, exists := k.Pressed[key]
return exists && stat
}
// OnKeyDown Attached to OnKeyDown event
func (k *Keys) OnKeyDown(key int) {
k.Pressed[key] = true
}
// OnKeyUp Attached to OnKeyUp event
func (k *Keys) OnKeyUp(key int) {
k.Pressed[key] = false
}