Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to get enter key event when using sdl.WaitEvent() #575

Open
Mariownyou opened this issue Jul 30, 2023 · 1 comment
Open

No way to get enter key event when using sdl.WaitEvent() #575

Mariownyou opened this issue Jul 30, 2023 · 1 comment

Comments

@Mariownyou
Copy link

Mariownyou commented Jul 30, 2023

Go version:
Go-SDL2 version:
SDL2 version:
OS: mac
Architecture: m1

for running {
	sdl.WaitEvent()
	// DrawMultilineText(text, surface, popup)

	RenderText(text, surface)
	window.UpdateSurface()

	for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
		switch event := event.(type) {
		case *sdl.KeyboardEvent:
			fmt.Println("Keyboard event") // does not work when waiting for events
			if event.Type == sdl.KEYDOWN {
				fmt.Println("Key pressed:", event.Keysym.Sym, text)
			}
		case *sdl.TextInputEvent:
			fmt.Println("Text input event", event.GetText()) // does not work when I don't wait for events but works when after sdl.WaitEvent()
		case *sdl.QuitEvent:
			running = false
		default:
			fmt.Println("Event type: ", event.GetType(), event) // does not work on Enter, when waiting for events
		}
	}

	sdl.Delay(delay)
}

Keyboard events such as Enter or Escape works fine when I don't wait for event. But if i use wait event, I can catch only text input events. moreover, text input events does not appear when I don't use wait for event.
@veeableful

@veeableful
Copy link
Contributor

Hi @Mariownyou, since you called sdl.WaitEvent() you can use the event returned from the function and check whether it is a KeyboardEvent for the Enter or Escape, using a switch case similar to the one used for sdl.PollEvent().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants