mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
Bug fix: Use prevent default properly
This commit is contained in:
parent
25cf2dab22
commit
59ed15b2f7
@ -81,23 +81,6 @@ func init() {
|
||||
})
|
||||
<-ch
|
||||
}
|
||||
doc.Call("addEventListener", "keydown", func(e js.Object) bool {
|
||||
code := e.Get("keyCode").Int()
|
||||
// Backspace
|
||||
if code == 8 {
|
||||
return false
|
||||
}
|
||||
// Functions
|
||||
if 112 <= code && code <= 123 {
|
||||
return false
|
||||
}
|
||||
// Alt and arrows
|
||||
if code == 37 && code == 39 {
|
||||
// Don't need to check Alt.
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
canvas = doc.Call("createElement", "canvas")
|
||||
canvas.Set("width", 16)
|
||||
@ -136,30 +119,30 @@ func init() {
|
||||
canvas.Get("style").Set("outline", "none")
|
||||
|
||||
// Keyboard
|
||||
canvas.Call("addEventListener", "keydown", func(e js.Object) bool {
|
||||
canvas.Call("addEventListener", "keydown", func(e js.Object) {
|
||||
e.Call("preventDefault")
|
||||
code := e.Get("keyCode").Int()
|
||||
currentInput.keyDown(code)
|
||||
return false
|
||||
})
|
||||
canvas.Call("addEventListener", "keyup", func(e js.Object) bool {
|
||||
canvas.Call("addEventListener", "keyup", func(e js.Object) {
|
||||
e.Call("preventDefault")
|
||||
code := e.Get("keyCode").Int()
|
||||
currentInput.keyUp(code)
|
||||
return false
|
||||
})
|
||||
|
||||
// Mouse
|
||||
canvas.Call("addEventListener", "mousedown", func(e js.Object) bool {
|
||||
canvas.Call("addEventListener", "mousedown", func(e js.Object) {
|
||||
e.Call("preventDefault")
|
||||
button := e.Get("button").Int()
|
||||
currentInput.mouseDown(button)
|
||||
return false
|
||||
})
|
||||
canvas.Call("addEventListener", "mouseup", func(e js.Object) bool {
|
||||
canvas.Call("addEventListener", "mouseup", func(e js.Object) {
|
||||
e.Call("preventDefault")
|
||||
button := e.Get("button").Int()
|
||||
currentInput.mouseUp(button)
|
||||
return false
|
||||
})
|
||||
canvas.Call("addEventListener", "contextmenu", func(e js.Object) bool {
|
||||
return false
|
||||
canvas.Call("addEventListener", "contextmenu", func(e js.Object) {
|
||||
e.Call("preventDefault")
|
||||
})
|
||||
|
||||
// Gamepad
|
||||
|
Loading…
Reference in New Issue
Block a user