Skip to content

Commit d949424

Browse files
committed
windows: use original ToUnicodeEx signature and update tests
1 parent 728fe38 commit d949424

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

windows/syscall_windows.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func NewCallbackCDecl(fn interface{}) uintptr {
216216
//sys LoadKeyboardLayout(name *uint16, flags uint32) (hkl Handle) = user32.LoadKeyboardLayoutW
217217
//sys UnloadKeyboardLayout(hkl Handle) (v bool) = user32.UnloadKeyboardLayout
218218
//sys GetKeyboardLayout(tid uint32) (hkl Handle) = user32.GetKeyboardLayout
219-
//sys toUnicodeEx(vkey uint32, scancode uint32, keystate *byte, pwszBuff *uint16, cchBuff int32, flags uint32, hkl Handle) (ret int32) = user32.ToUnicodeEx
219+
//sys ToUnicodeEx(vkey uint32, scancode uint32, keystate *byte, pwszBuff *uint16, cchBuff int32, flags uint32, hkl Handle) (ret int32) = user32.ToUnicodeEx
220220
//sys GetShellWindow() (shellWindow HWND) = user32.GetShellWindow
221221
//sys MessageBox(hwnd HWND, text *uint16, caption *uint16, boxtype uint32) (ret int32, err error) [failretval==0] = user32.MessageBoxW
222222
//sys ExitWindowsEx(flags uint32, reason uint32) (err error) = user32.ExitWindowsEx
@@ -1924,12 +1924,3 @@ const (
19241924
EV_ERR = 0x0080
19251925
EV_RING = 0x0100
19261926
)
1927-
1928-
// ToUnicodeEx Translates the specified virtual-key code and keyboard state to
1929-
// the corresponding Unicode character or characters.
1930-
func ToUnicodeEx(virtualKey, scanCode uint32, keyState [256]byte, buf []uint16, flags uint32, layout Handle) int32 {
1931-
if len(buf) == 0 {
1932-
return 0
1933-
}
1934-
return toUnicodeEx(virtualKey, scanCode, &keyState[0], &buf[0], int32(len(buf)), flags, layout)
1935-
}

windows/syscall_windows_test.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -1289,13 +1289,18 @@ func TestGetKeyboardLayout(t *testing.T) {
12891289

12901290
func TestToUnicodeEx(t *testing.T) {
12911291
var utf16Buf [16]uint16
1292-
const araLayout = windows.Handle(0x401)
1292+
ara, err := windows.UTF16PtrFromString("00000401") // ara layout 0x401
1293+
if err != nil {
1294+
t.Fatalf("UTF16PtrFromString failed: %v", err)
1295+
}
1296+
araLayout := windows.LoadKeyboardLayout(ara, 0)
12931297
var keyState [256]byte
12941298
ret := windows.ToUnicodeEx(
12951299
0x41, // 'A' vkCode
12961300
0x1e, // 'A' scanCode
1297-
keyState,
1298-
utf16Buf[:],
1301+
&keyState[0],
1302+
&utf16Buf[0],
1303+
int32(len(utf16Buf)),
12991304
0x4, // don't change keyboard state
13001305
araLayout,
13011306
)
@@ -1306,4 +1311,7 @@ func TestToUnicodeEx(t *testing.T) {
13061311
if utf16Buf[0] != 'ش' {
13071312
t.Errorf("ToUnicodeEx failed, wanted 'ش', got %q", utf16Buf[0])
13081313
}
1314+
if !windows.UnloadKeyboardLayout(araLayout) {
1315+
t.Errorf("UnloadKeyboardLayout failed")
1316+
}
13091317
}

windows/zsyscall_windows.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)