ui: Bug fix: Focus canvas explicitly on input

Fixes #961
This commit is contained in:
Hajime Hoshi 2019-10-15 23:57:14 +09:00
parent 75721e6fc1
commit 72248fa3ef

View File

@ -338,6 +338,9 @@ func init() {
// Keyboard // Keyboard
canvas.Call("addEventListener", "keydown", js.FuncOf(func(this js.Value, args []js.Value) interface{} { canvas.Call("addEventListener", "keydown", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
// Focus the canvas explicitly to activate tha game (#961).
canvas.Call("focus")
e := args[0] e := args[0]
// Don't 'preventDefault' on keydown events or keypress events wouldn't work (#715). // Don't 'preventDefault' on keydown events or keypress events wouldn't work (#715).
theUI.input.Update(e) theUI.input.Update(e)
@ -358,6 +361,9 @@ func init() {
// Mouse // Mouse
canvas.Call("addEventListener", "mousedown", js.FuncOf(func(this js.Value, args []js.Value) interface{} { canvas.Call("addEventListener", "mousedown", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
// Focus the canvas explicitly to activate tha game (#961).
canvas.Call("focus")
e := args[0] e := args[0]
e.Call("preventDefault") e.Call("preventDefault")
theUI.input.Update(e) theUI.input.Update(e)
@ -384,6 +390,9 @@ func init() {
// Touch // Touch
canvas.Call("addEventListener", "touchstart", js.FuncOf(func(this js.Value, args []js.Value) interface{} { canvas.Call("addEventListener", "touchstart", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
// Focus the canvas explicitly to activate tha game (#961).
canvas.Call("focus")
e := args[0] e := args[0]
e.Call("preventDefault") e.Call("preventDefault")
theUI.input.Update(e) theUI.input.Update(e)