From 6522994a1f3664923fbfd713205cc66da01faefb Mon Sep 17 00:00:00 2001 From: Karutoh Date: Sat, 27 Jul 2024 10:12:10 -0700 Subject: [PATCH] Fixed Win32 keyboard input. --- src/io/Window_W32.cpp | 111 +++++++++++++++++++++++++++++++++++++++- src/io/hid/Keyboard.cpp | 8 +-- 2 files changed, 113 insertions(+), 6 deletions(-) diff --git a/src/io/Window_W32.cpp b/src/io/Window_W32.cpp index ac15850..8ff2747 100644 --- a/src/io/Window_W32.cpp +++ b/src/io/Window_W32.cpp @@ -383,7 +383,7 @@ namespace ehs rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC; rid[0].usUsage = HID_USAGE_GENERIC_MOUSE; - rid[0].dwFlags = RIDEV_INPUTSINK; + rid[0].dwFlags = 0; rid[0].hwndTarget = hdl; rid[1].usUsagePage = HID_USAGE_PAGE_GENERIC; @@ -703,11 +703,118 @@ namespace ehs Serializer Window::GetClipboard() { - return {}; + if (!OpenClipboard(hdl)) + { + EHS_LOG_INT(LogType::ERR, 0, "Failed to open Clipboard with error #" + Str_8::FromNum(GetLastError()) + "."); + return {}; + } + + HANDLE hData = GetClipboardData(CF_TEXT); + if (!hData) + { + EHS_LOG_INT(LogType::ERR, 1, "Failed to get clipboard handle with error #" + Str_8::FromNum(GetLastError()) + "."); + + if (!CloseClipboard()) + EHS_LOG_INT(LogType::ERR, 4, "Failed to close clipboard with error #" + Str_8::FromNum(GetLastError()) + "."); + + return {}; + } + + Char_8* text = (Char_8 *)GlobalLock(hData); + if (!text) + { + EHS_LOG_INT(LogType::ERR, 2, "Failed to get clipboard data with error #" + Str_8::FromNum(GetLastError()) + "."); + return {}; + } + + Serializer data(Endianness::LE, (Byte *)text, Str_8::Len(text)); + + if (!GlobalUnlock(hData)) + { + EHS_LOG_INT(LogType::ERR, 3, "Failed to free clipboard data with error #" + Str_8::FromNum(GetLastError()) + "."); + + return data; + } + + if (!CloseClipboard()) + { + EHS_LOG_INT(LogType::ERR, 4, "Failed to close clipboard with error #" + Str_8::FromNum(GetLastError()) + "."); + + return data; + } + + EHS_LOG_SUCCESS(); + + return data; } void Window::SetClipboard(Serializer data) { + if (!OpenClipboard(hdl)) + { + EHS_LOG_INT(LogType::ERR, 0, "Failed to open Clipboard with error #" + Str_8::FromNum(GetLastError()) + "."); + return; + } + + if (!EmptyClipboard()) + { + EHS_LOG_INT(LogType::ERR, 1, "Failed to empty clipboard with error #" + Str_8::FromNum(GetLastError()) + "."); + + if (!CloseClipboard()) + EHS_LOG_INT(LogType::ERR, 6, "Failed to close clipboard with error #" + Str_8::FromNum(GetLastError()) + "."); + + return; + } + + HGLOBAL hGlob = GlobalAlloc(GMEM_MOVEABLE, data.Size()); + if (!hGlob) + { + EHS_LOG_INT(LogType::ERR, 2, "Failed to allocate clipboard data with error #" + Str_8::FromNum(GetLastError()) + "."); + + if (!CloseClipboard()) + EHS_LOG_INT(LogType::ERR, 6, "Failed to close clipboard with error #" + Str_8::FromNum(GetLastError()) + "."); + + return; + } + + Byte* result = (Byte *)GlobalLock(hGlob); + if (!result) + { + EHS_LOG_INT(LogType::ERR, 3, "Failed to lock data with error #" + Str_8::FromNum(GetLastError()) + "."); + + GlobalFree(hGlob); + + if (!CloseClipboard()) + EHS_LOG_INT(LogType::ERR, 6, "Failed to close clipboard with error #" + Str_8::FromNum(GetLastError()) + "."); + + return; + } + + Util::Copy(result, &data[0], data.Size()); + + GlobalUnlock(hGlob); + + HANDLE hData = SetClipboardData(CF_TEXT, hGlob); + if (!hData) + { + EHS_LOG_INT(LogType::ERR, 5, "Failed to get clipboard handle with error #" + Str_8::FromNum(GetLastError()) + "."); + + GlobalFree(hGlob); + + if (!CloseClipboard()) + EHS_LOG_INT(LogType::ERR, 6, "Failed to close clipboard with error #" + Str_8::FromNum(GetLastError()) + "."); + + return; + } + + if (!CloseClipboard()) + { + EHS_LOG_INT(LogType::ERR, 6, "Failed to close clipboard with error #" + Str_8::FromNum(GetLastError()) + "."); + + return; + } + + EHS_LOG_SUCCESS(); } void Window::SetCursorImg(CursorImg img) diff --git a/src/io/hid/Keyboard.cpp b/src/io/hid/Keyboard.cpp index 125400c..840f78b 100644 --- a/src/io/hid/Keyboard.cpp +++ b/src/io/hid/Keyboard.cpp @@ -268,23 +268,23 @@ namespace ehs case 71: return Keyboard::F13; case 72: - return Keyboard::F14; + return Keyboard::Up; case 73: return Keyboard::F15; case 74: return Keyboard::F16; case 75: - return Keyboard::F17; + return Keyboard::Left; case 76: return Keyboard::F18; case 77: - return Keyboard::F19; + return Keyboard::Right; case 78: return Keyboard::F20; case 79: return Keyboard::F21; case 80: - return Keyboard::F22; + return Keyboard::Down; case 81: return Keyboard::F23; case 82: