mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +00:00
app/internal/window: (wasm) generate key.Events for all printable characters
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -4,9 +4,12 @@ package window
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall/js"
|
"syscall/js"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"gioui.org/f32"
|
"gioui.org/f32"
|
||||||
"gioui.org/io/key"
|
"gioui.org/io/key"
|
||||||
@@ -396,15 +399,6 @@ func Main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func translateKey(k string) (string, bool) {
|
func translateKey(k string) (string, bool) {
|
||||||
if len(k) == 1 {
|
|
||||||
c := k[0]
|
|
||||||
if '0' <= c && c <= '9' || 'A' <= c && c <= 'Z' {
|
|
||||||
return string(c), true
|
|
||||||
}
|
|
||||||
if 'a' <= c && c <= 'z' {
|
|
||||||
return string(c - 0x20), true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var n string
|
var n string
|
||||||
switch k {
|
switch k {
|
||||||
case "ArrowUp":
|
case "ArrowUp":
|
||||||
@@ -438,6 +432,11 @@ func translateKey(k string) (string, bool) {
|
|||||||
case "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12":
|
case "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12":
|
||||||
n = k
|
n = k
|
||||||
default:
|
default:
|
||||||
|
r, s := utf8.DecodeRuneInString(k)
|
||||||
|
// If there is exactly one printable character, return that.
|
||||||
|
if s == len(k) && unicode.IsPrint(r) {
|
||||||
|
return strings.ToUpper(k), true
|
||||||
|
}
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
return n, true
|
return n, true
|
||||||
|
|||||||
Reference in New Issue
Block a user