Skip to content

Commit

Permalink
v0.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkauzh committed Oct 11, 2023
1 parent e89c94a commit 2b5e169
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/webzen/keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

var keyPressed = make(map[string]bool)
var pressed = false

func SetupEventListeners() {
// Initialize event listeners once
Expand Down Expand Up @@ -37,3 +38,15 @@ func SetupEventListeners() {
func KeyPressed(key string) bool {
return keyPressed[key]
}

func KeyPressedOnce(key string) bool {
if !pressed && KeyPressed(key) {
pressed = true
return true
} else if !KeyPressed(key) {
pressed = false
return false
}

return false
}
2 changes: 1 addition & 1 deletion tests/test1/test1.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
tools.Print("Button pressed")
})

if keys.KeyPressed("a") {
if keys.KeyPressedOnce("a") {
tools.Print("A key pressed")
}
webzen.Update()
Expand Down

0 comments on commit 2b5e169

Please sign in to comment.