mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
Bug fix: Use prevent default properly
This commit is contained in:
parent
25cf2dab22
commit
59ed15b2f7
@ -81,23 +81,6 @@ func init() {
|
|||||||
})
|
})
|
||||||
<-ch
|
<-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 = doc.Call("createElement", "canvas")
|
||||||
canvas.Set("width", 16)
|
canvas.Set("width", 16)
|
||||||
@ -136,30 +119,30 @@ func init() {
|
|||||||
canvas.Get("style").Set("outline", "none")
|
canvas.Get("style").Set("outline", "none")
|
||||||
|
|
||||||
// Keyboard
|
// 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()
|
code := e.Get("keyCode").Int()
|
||||||
currentInput.keyDown(code)
|
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()
|
code := e.Get("keyCode").Int()
|
||||||
currentInput.keyUp(code)
|
currentInput.keyUp(code)
|
||||||
return false
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Mouse
|
// 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()
|
button := e.Get("button").Int()
|
||||||
currentInput.mouseDown(button)
|
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()
|
button := e.Get("button").Int()
|
||||||
currentInput.mouseUp(button)
|
currentInput.mouseUp(button)
|
||||||
return false
|
|
||||||
})
|
})
|
||||||
canvas.Call("addEventListener", "contextmenu", func(e js.Object) bool {
|
canvas.Call("addEventListener", "contextmenu", func(e js.Object) {
|
||||||
return false
|
e.Call("preventDefault")
|
||||||
})
|
})
|
||||||
|
|
||||||
// Gamepad
|
// Gamepad
|
||||||
|
Loading…
Reference in New Issue
Block a user