mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
|
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||||
"github.com/hajimehoshi/ebiten/examples/keyboard/keyboard"
|
"github.com/hajimehoshi/ebiten/examples/keyboard/keyboard"
|
||||||
rkeyabord "github.com/hajimehoshi/ebiten/examples/resources/images/keyboard"
|
rkeyabord "github.com/hajimehoshi/ebiten/examples/resources/images/keyboard"
|
||||||
)
|
)
|
||||||
@ -44,7 +46,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
func update(screen *ebiten.Image) error {
|
||||||
// Collect pressed keys' names.
|
|
||||||
pressed := []ebiten.Key{}
|
pressed := []ebiten.Key{}
|
||||||
for k := ebiten.Key(0); k <= ebiten.KeyMax; k++ {
|
for k := ebiten.Key(0); k <= ebiten.KeyMax; k++ {
|
||||||
if ebiten.IsKeyPressed(k) {
|
if ebiten.IsKeyPressed(k) {
|
||||||
@ -81,6 +82,12 @@ func update(screen *ebiten.Image) error {
|
|||||||
screen.DrawImage(keyboardImage, op)
|
screen.DrawImage(keyboardImage, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keyStrs := []string{}
|
||||||
|
for _, p := range pressed {
|
||||||
|
keyStrs = append(keyStrs, p.String())
|
||||||
|
}
|
||||||
|
ebitenutil.DebugPrint(screen, strings.Join(keyStrs, ", "))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
input.go
3
input.go
@ -35,6 +35,9 @@ func InputChars() []rune {
|
|||||||
|
|
||||||
// IsKeyPressed returns a boolean indicating whether key is pressed.
|
// 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.
|
// This function is concurrent-safe.
|
||||||
func IsKeyPressed(key Key) bool {
|
func IsKeyPressed(key Key) bool {
|
||||||
return input.Get().IsKeyPressed(input.Key(key))
|
return input.Get().IsKeyPressed(input.Key(key))
|
||||||
|
Loading…
Reference in New Issue
Block a user