mirror of
https://github.com/golang/sys.git
synced 2026-02-08 11:46:04 +03:00
windows: use original ToUnicodeEx signature and update tests
This commit is contained in:
@@ -216,7 +216,7 @@ func NewCallbackCDecl(fn interface{}) uintptr {
|
||||
//sys LoadKeyboardLayout(name *uint16, flags uint32) (hkl Handle) = user32.LoadKeyboardLayoutW
|
||||
//sys UnloadKeyboardLayout(hkl Handle) (v bool) = user32.UnloadKeyboardLayout
|
||||
//sys GetKeyboardLayout(tid uint32) (hkl Handle) = user32.GetKeyboardLayout
|
||||
//sys toUnicodeEx(vkey uint32, scancode uint32, keystate *byte, pwszBuff *uint16, cchBuff int32, flags uint32, hkl Handle) (ret int32) = user32.ToUnicodeEx
|
||||
//sys ToUnicodeEx(vkey uint32, scancode uint32, keystate *byte, pwszBuff *uint16, cchBuff int32, flags uint32, hkl Handle) (ret int32) = user32.ToUnicodeEx
|
||||
//sys GetShellWindow() (shellWindow HWND) = user32.GetShellWindow
|
||||
//sys MessageBox(hwnd HWND, text *uint16, caption *uint16, boxtype uint32) (ret int32, err error) [failretval==0] = user32.MessageBoxW
|
||||
//sys ExitWindowsEx(flags uint32, reason uint32) (err error) = user32.ExitWindowsEx
|
||||
@@ -1924,12 +1924,3 @@ const (
|
||||
EV_ERR = 0x0080
|
||||
EV_RING = 0x0100
|
||||
)
|
||||
|
||||
// ToUnicodeEx Translates the specified virtual-key code and keyboard state to
|
||||
// the corresponding Unicode character or characters.
|
||||
func ToUnicodeEx(virtualKey, scanCode uint32, keyState [256]byte, buf []uint16, flags uint32, layout Handle) int32 {
|
||||
if len(buf) == 0 {
|
||||
return 0
|
||||
}
|
||||
return toUnicodeEx(virtualKey, scanCode, &keyState[0], &buf[0], int32(len(buf)), flags, layout)
|
||||
}
|
||||
|
||||
@@ -1289,13 +1289,18 @@ func TestGetKeyboardLayout(t *testing.T) {
|
||||
|
||||
func TestToUnicodeEx(t *testing.T) {
|
||||
var utf16Buf [16]uint16
|
||||
const araLayout = windows.Handle(0x401)
|
||||
ara, err := windows.UTF16PtrFromString("00000401") // ara layout 0x401
|
||||
if err != nil {
|
||||
t.Fatalf("UTF16PtrFromString failed: %v", err)
|
||||
}
|
||||
araLayout := windows.LoadKeyboardLayout(ara, 0)
|
||||
var keyState [256]byte
|
||||
ret := windows.ToUnicodeEx(
|
||||
0x41, // 'A' vkCode
|
||||
0x1e, // 'A' scanCode
|
||||
keyState,
|
||||
utf16Buf[:],
|
||||
&keyState[0],
|
||||
&utf16Buf[0],
|
||||
int32(len(utf16Buf)),
|
||||
0x4, // don't change keyboard state
|
||||
araLayout,
|
||||
)
|
||||
@@ -1306,4 +1311,7 @@ func TestToUnicodeEx(t *testing.T) {
|
||||
if utf16Buf[0] != 'ش' {
|
||||
t.Errorf("ToUnicodeEx failed, wanted 'ش', got %q", utf16Buf[0])
|
||||
}
|
||||
if !windows.UnloadKeyboardLayout(araLayout) {
|
||||
t.Errorf("UnloadKeyboardLayout failed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4131,7 +4131,7 @@ func MessageBox(hwnd HWND, text *uint16, caption *uint16, boxtype uint32) (ret i
|
||||
return
|
||||
}
|
||||
|
||||
func toUnicodeEx(vkey uint32, scancode uint32, keystate *byte, pwszBuff *uint16, cchBuff int32, flags uint32, hkl Handle) (ret int32) {
|
||||
func ToUnicodeEx(vkey uint32, scancode uint32, keystate *byte, pwszBuff *uint16, cchBuff int32, flags uint32, hkl Handle) (ret int32) {
|
||||
r0, _, _ := syscall.Syscall9(procToUnicodeEx.Addr(), 7, uintptr(vkey), uintptr(scancode), uintptr(unsafe.Pointer(keystate)), uintptr(unsafe.Pointer(pwszBuff)), uintptr(cchBuff), uintptr(flags), uintptr(hkl), 0, 0)
|
||||
ret = int32(r0)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user