-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_manager.go
49 lines (47 loc) · 1.36 KB
/
event_manager.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
41
42
43
44
45
46
47
48
49
package dosktop
import (
"github.com/supercom32/dosktop/internal/memory"
"fmt"
"github.com/gdamore/tcell"
"strings"
)
/*
updateEventQueues allows you to update all event queues so that information
such as mouse clicks, keystrokes, and other events are properly registered.
*/
func updateEventQueues() {
event := commonResource.screen.PollEvent()
switch event := event.(type) {
case *tcell.EventResize:
commonResource.screen.Sync()
case *tcell.EventKey:
keystroke := ""
if strings.Contains(event.Name(), "Rune") {
keystroke = fmt.Sprintf("%c", event.Rune())
} else {
keystroke = strings.ToLower(event.Name())
}
memory.KeyboardMemory.AddKeystrokeToKeyboardBuffer(keystroke)
case *tcell.EventMouse:
mouseXLocation, mouseYLocation := event.Position()
var mouseButtonNumber uint
mouseButton := event.Buttons()
for index := uint(0); index < 8; index++ {
if int(mouseButton)&(1<<index) != 0 {
mouseButtonNumber = index + 1
}
}
wheelState := ""
if mouseButton&tcell.WheelUp != 0 {
wheelState = "Up"
} else if mouseButton&tcell.WheelDown != 0 {
wheelState = "Down"
} else if mouseButton&tcell.WheelLeft != 0 {
wheelState = "Left"
} else if mouseButton&tcell.WheelRight != 0 {
wheelState = "Right"
}
memory.MouseMemory.SetMouseStatus(mouseXLocation, mouseYLocation, mouseButtonNumber, wheelState)
updateButtonStates()
}
}