diff --git a/lib/input/keyboard.go b/lib/input/keyboard.go index 85b36659..7edf4288 100644 --- a/lib/input/keyboard.go +++ b/lib/input/keyboard.go @@ -78,7 +78,7 @@ func (k Key) Shift() (Key, bool) { // Printable returns true if the key is printable. func (k Key) Printable() bool { - return len(k.Info().Key) == 1 + return len([]rune(k.Info().Key)) == 1 } // Modifier returns the modifier value of the key. diff --git a/lib/input/keyboard_test.go b/lib/input/keyboard_test.go index 133b36f9..c0f88f56 100644 --- a/lib/input/keyboard_test.go +++ b/lib/input/keyboard_test.go @@ -1,6 +1,7 @@ package input_test import ( + "fmt" "testing" "github.com/go-rod/rod/lib/input" @@ -147,3 +148,36 @@ func TestMac(t *testing.T) { }, }) } + +func TestMultiByteChars(t *testing.T) { + g := got.T(t) + // Cyrillic chars is multiByte + lower := 'б' + upper := 'Б' + lowerStr := string(lower) + upperStr := string(upper) + + code := fmt.Sprintf("Key%s", upperStr) + + keyCode := int(upper) + k := input.AddKey(lowerStr, upperStr, code, keyCode, 0) + + g.Eq(k.Info(), input.KeyInfo{ + Key: "б", + Code: "KeyБ", + KeyCode: 1041, + Location: 0, + }) + + g.True(k.Printable()) + + g.Eq(k.Encode(proto.InputDispatchKeyEventTypeKeyDown, 0), &proto.InputDispatchKeyEvent{ + Type: "keyDown", + Text: "б", + UnmodifiedText: "б", + Code: "KeyБ", + Key: "б", + WindowsVirtualKeyCode: 1041, + Location: gson.Int(0), + }) +}