Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/input/keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 34 additions & 0 deletions lib/input/keyboard_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package input_test

import (
"fmt"
"testing"

"github.com/go-rod/rod/lib/input"
Expand Down Expand Up @@ -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),
})
}