Skip to content

Commit

Permalink
windows: change exported ToUnicodeEx signature + fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed May 17, 2024
1 parent 3aa85da commit d4d009a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 1 addition & 2 deletions windows/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -1925,10 +1925,9 @@ const (

// ToUnicodeEx Translates the specified virtual-key code and keyboard state to
// the corresponding Unicode character or characters.
func ToUnicodeEx(virtualKey, scanCode uint32, buf []uint16, flags uint32, layout Handle) int32 {
func ToUnicodeEx(virtualKey, scanCode uint32, keyState [256]byte, buf []uint16, flags uint32, layout Handle) int32 {
if len(buf) == 0 {
return 0
}
var keyState [256]byte
return toUnicodeEx(virtualKey, scanCode, &keyState[0], &buf[0], int32(len(buf)), flags, layout)
}
5 changes: 4 additions & 1 deletion windows/syscall_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1283,17 +1283,20 @@ func TestGetKeyboardLayout(t *testing.T) {
t.Fatalf("GetWindowThreadProcessId failed: %v", err)
}

// We don't care about the result, just that it doesn't crash.
_ = windows.GetKeyboardLayout(tid)
}

func TestToUnicodeEx(t *testing.T) {
var utf16Buf [16]uint16
const araLayout = windows.Handle(0x401)
var keyState [256]byte
ret := windows.ToUnicodeEx(
0x41, // 'A' vkCode
0x1e, // 'A' scanCode
keyState,
utf16Buf[:],
0,
0x4, // don't change keyboard state
araLayout,
)

Expand Down

0 comments on commit d4d009a

Please sign in to comment.