internal/glfwwin: remove an unused function GetKeyName

MapVirtualKeyW is not available on Xbox.

Updates #2084
This commit is contained in:
Hajime Hoshi 2022-05-25 00:57:04 +09:00
parent ffc9a0876a
commit 847357c3ea
5 changed files with 9 additions and 66 deletions

View File

@ -842,7 +842,6 @@ var (
procSetWindowTextW = user32.NewProc("SetWindowTextW")
procShowWindow = user32.NewProc("ShowWindow")
procSystemParametersInfoW = user32.NewProc("SystemParametersInfoW")
procToUnicode = user32.NewProc("ToUnicode")
procTranslateMessage = user32.NewProc("TranslateMessage")
procTrackMouseEvent = user32.NewProc("TrackMouseEvent")
procUnregisterClassW = user32.NewProc("UnregisterClassW")
@ -1463,6 +1462,10 @@ func _MapVirtualKeyW(uCode uint32, uMapType uint32) uint32 {
return uint32(r)
}
func _MapVirtualKeyW_Available() bool {
return procMapVirtualKeyW.Find() == nil
}
func _MonitorFromWindow(hwnd windows.HWND, dwFlags uint32) _HMONITOR {
r, _, _ := procMonitorFromWindow.Call(uintptr(hwnd), uintptr(dwFlags))
return _HMONITOR(r)
@ -1797,12 +1800,6 @@ func _TlsSetValue(dwTlsIndex uint32, lpTlsValue uintptr) error {
return nil
}
func _ToUnicode(wVirtKey uint32, wScanCode uint32, lpKeyState *byte, pwszBuff *uint16, cchBuff int32, wFlags uint32) int32 {
r, _, _ := procToUnicode.Call(uintptr(wVirtKey), uintptr(wScanCode),
uintptr(unsafe.Pointer(lpKeyState)), uintptr(unsafe.Pointer(pwszBuff)), uintptr(cchBuff), uintptr(wFlags))
return int32(r)
}
func _TranslateMessage(lpMsg *_MSG) bool {
r, _, _ := procTranslateMessage.Call(uintptr(unsafe.Pointer(lpMsg)))
return int32(r) != 0

View File

@ -258,20 +258,7 @@ func RawMouseMotionSupported() (bool, error) {
return platformRawMouseMotionSupported(), nil
}
func GetKeyName(key Key, scancode int) (string, error) {
if !_glfw.initialized {
return "", NotInitialized
}
if key != KeyUnknown {
if key != KeyKPEqual && (key < KeyKP0 || key > KeyKPAdd) && (key < KeyApostrophe || key > KeyWorld2) {
return "", nil
}
scancode = platformGetKeyScancode(key)
}
return platformGetScancodeName(scancode)
}
// GetKeyName is not implemented.
func GetKeyScancode(key Key) (int, error) {
if !_glfw.initialized {

View File

@ -285,7 +285,6 @@ type library struct {
clipboardString string
keycodes [512]Key
scancodes [KeyLast + 1]int
keynames [KeyLast + 1]string
// Where to place the cursor when re-enabled
restoreCursorPosX float64

View File

@ -212,41 +212,6 @@ func createHelperWindow() error {
return nil
}
func updateKeyNamesWin32() {
var state [256]byte
for key := KeySpace; key <= KeyLast; key++ {
scancode := _glfw.win32.scancodes[key]
if scancode == -1 {
continue
}
var vk uint32
if key >= KeyKP0 && key <= KeyKPAdd {
vks := []uint32{
_VK_NUMPAD0, _VK_NUMPAD1, _VK_NUMPAD2, _VK_NUMPAD3,
_VK_NUMPAD4, _VK_NUMPAD5, _VK_NUMPAD6, _VK_NUMPAD7,
_VK_NUMPAD8, _VK_NUMPAD9, _VK_DECIMAL, _VK_DIVIDE,
_VK_MULTIPLY, _VK_SUBTRACT, _VK_ADD,
}
vk = vks[key-KeyKP0]
} else {
vk = _MapVirtualKeyW(uint32(scancode), _MAPVK_VSC_TO_VK)
}
var chars [16]uint16
length := _ToUnicode(vk, uint32(scancode), &state[0], &chars[0], int32(len(chars)), 0)
if length == -1 {
// TODO: Why is ToUnicode called twice?
length = _ToUnicode(vk, uint32(scancode), &state[0], &chars[0], int32(len(chars)), 0)
}
if length < 1 {
continue
}
_glfw.win32.keynames[key] = windows.UTF16ToString(chars[:1])
}
}
func isWindowsVersionOrGreaterWin32(major, minor, sp uint16) bool {
osvi := _OSVERSIONINFOEXW{
dwMajorVersion: uint32(major),
@ -287,7 +252,6 @@ func platformInit() error {
// See https://github.com/glfw/glfw/commit/58b48a3a00d9c2a5ca10cc23069a71d8773cc7a4
createKeyTables()
updateKeyNamesWin32()
if isWindows10CreatorsUpdateOrGreaterWin32() {
if err := _SetProcessDpiAwarenessContext(_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); err != nil && !errors.Is(err, windows.ERROR_ACCESS_DENIED) {

View File

@ -688,7 +688,7 @@ func windowProc(hWnd windows.HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM)
return 0
case _WM_INPUTLANGCHANGE:
updateKeyNamesWin32()
// Do nothing
case _WM_CHAR, _WM_SYSCHAR:
if wParam >= 0xd800 && wParam <= 0xdbff {
@ -732,6 +732,9 @@ func windowProc(hWnd windows.HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM)
scancode := uint32((_HIWORD(uint32(lParam)) & (_KF_EXTENDED | 0xff)))
if scancode == 0 {
if !_MapVirtualKeyW_Available() {
break
}
// NOTE: Some synthetic key messages have a scancode of zero
// HACK: Map the virtual key back to a usable scancode
scancode = _MapVirtualKeyW(uint32(wParam), _MAPVK_VK_TO_VSC)
@ -2121,13 +2124,6 @@ func (w *Window) platformSetCursorMode(mode int) error {
return nil
}
func platformGetScancodeName(scancode int) (string, error) {
if scancode < 0 || scancode > (_KF_EXTENDED|0xff) || _glfw.win32.keycodes[scancode] == KeyUnknown {
return "", fmt.Errorf("glfwwin: invalid scancode: %d", scancode)
}
return _glfw.win32.keynames[_glfw.win32.keycodes[scancode]], nil
}
func platformGetKeyScancode(key Key) int {
return _glfw.win32.scancodes[key]
}