mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
examples/keyboard: Show other keys than 'keyboard' keys
This commit is contained in:
parent
bf304e6ac8
commit
fac7651152
@ -21,8 +21,10 @@ import (
|
||||
"image"
|
||||
_ "image/png"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/examples/keyboard/keyboard"
|
||||
rkeyabord "github.com/hajimehoshi/ebiten/examples/resources/images/keyboard"
|
||||
)
|
||||
@ -44,7 +46,6 @@ func init() {
|
||||
}
|
||||
|
||||
func update(screen *ebiten.Image) error {
|
||||
// Collect pressed keys' names.
|
||||
pressed := []ebiten.Key{}
|
||||
for k := ebiten.Key(0); k <= ebiten.KeyMax; k++ {
|
||||
if ebiten.IsKeyPressed(k) {
|
||||
@ -81,6 +82,12 @@ func update(screen *ebiten.Image) error {
|
||||
screen.DrawImage(keyboardImage, op)
|
||||
}
|
||||
|
||||
keyStrs := []string{}
|
||||
for _, p := range pressed {
|
||||
keyStrs = append(keyStrs, p.String())
|
||||
}
|
||||
ebitenutil.DebugPrint(screen, strings.Join(keyStrs, ", "))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
3
input.go
3
input.go
@ -35,6 +35,9 @@ func InputChars() []rune {
|
||||
|
||||
// IsKeyPressed returns a boolean indicating whether key is pressed.
|
||||
//
|
||||
// Known issue: On Edge browser, KeyKPEnter and KeyKPEqual don't work well.
|
||||
// These keys are recognized as KeyEnter and KeyEqual.
|
||||
//
|
||||
// This function is concurrent-safe.
|
||||
func IsKeyPressed(key Key) bool {
|
||||
return input.Get().IsKeyPressed(input.Key(key))
|
||||
|
Loading…
Reference in New Issue
Block a user