From 2b5e1699ea02a0266292ed69539344ff85feceeb Mon Sep 17 00:00:00 2001 From: Dima Marhitych Date: Wed, 11 Oct 2023 17:23:34 +0200 Subject: [PATCH] v0.0.11 --- src/webzen/keys/keys.go | 13 +++++++++++++ tests/test1/test1.go | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/webzen/keys/keys.go b/src/webzen/keys/keys.go index 06aef74..bf51400 100644 --- a/src/webzen/keys/keys.go +++ b/src/webzen/keys/keys.go @@ -10,6 +10,7 @@ import ( ) var keyPressed = make(map[string]bool) +var pressed = false func SetupEventListeners() { // Initialize event listeners once @@ -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 +} diff --git a/tests/test1/test1.go b/tests/test1/test1.go index 778beb0..acd968a 100644 --- a/tests/test1/test1.go +++ b/tests/test1/test1.go @@ -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()