// // lib/utils/winkey_blocker.dart // import 'dart:ffi'; // import 'dart:io'; // import 'package:ffi/ffi.dart'; // // // Windows API 상수 // const int WH_KEYBOARD_LL = 13; // const int HC_ACTION = 0; // const int WM_KEYDOWN = 0x0100; // const int WM_SYSKEYDOWN = 0x0104; // // const int VK_LWIN = 0x5B; // Left Windows Key // const int VK_RWIN = 0x5C; // Right Windows Key // // // KBDLLHOOKSTRUCT 정의 // base class KBDLLHOOKSTRUCT extends Struct { // @Int32() // external int vkCode; // @Int32() // external int scanCode; // @Int32() // external int flags; // @Int32() // external int time; // @Uint64() // external int dwExtraInfo; // } // // // HHOOK 타입 (void*) // typedef HHOOK = Pointer; // typedef HMODULE = Pointer; // typedef HWND = Pointer; // // // SetWindowsHookEx 타입 // typedef SetWindowsHookExFunc = Pointer Function( // Int32 idHook, // Pointer callback, // HMODULE hMod, // Int32 dwThreadId, // ); // typedef SetWindowsHookExDart = Pointer Function( // int idHook, // Pointer callback, // HMODULE hMod, // int dwThreadId, // ); // // // CallNextHookEx 타입 // typedef CallNextHookExFunc = Int32 Function( // HHOOK hhk, // Int32 nCode, // Int32 wParam, // Pointer lParam, // ); // typedef CallNextHookExDart = int Function( // Pointer hhk, // int nCode, // int wParam, // Pointer lParam, // ); // // // GetModuleHandle 타입 // typedef GetModuleHandleFunc = HMODULE Function(Pointer lpModuleName); // typedef GetModuleHandleDart = Pointer Function(Pointer lpModuleName); // // // UnhookWindowsHookEx 타입 // typedef UnhookWindowsHookExFunc = Int32 Function(HHOOK hhk); // typedef UnhookWindowsHookExDart = int Function(Pointer hhk); // typedef KeyboardHookProc = Int32 Function( // Int32 nCode, // Int32 wParam, // Pointer lParam, // ); // // /// 윈도우키 차단기 // class WinKeyBlocker { // static Pointer? _hookHandle; // static Pointer>? _callbackPtr; // // // 저수준 키보드 콜백 타입 // // static int _keyboardHookCallback( // int nCode, // int wParam, // Pointer lParam, // ) { // if (nCode == HC_ACTION) { // final vkCode = lParam.ref.vkCode; // // if (vkCode == VK_LWIN || vkCode == VK_RWIN) { // print('[BLOCKED] Windows Key (VK: $vkCode)'); // return 1; // ✅ 차단 // } // } // // // 다음 훅으로 전달 // return _callNextHookEx!.call( // _hookHandle!.cast(), // nCode, // wParam, // lParam.cast(), // ); // } // // // API 포인터 // static SetWindowsHookExDart? _setHook; // static CallNextHookExDart? _callNextHookEx; // static GetModuleHandleDart? _getModuleHandle; // static UnhookWindowsHookExDart? _unhookHook; // // // DLL 핸들 // static DynamicLibrary? _user32; // // /// 초기화: DLL 로드 및 함수 바인딩 // static void _loadLibraries() { // if (_setHook != null) return; // 이미 로드됨 // // _user32 = DynamicLibrary.open('user32.dll'); // // _setHook = _user32! // .lookup>('SetWindowsHookExW') // .asFunction(); // // // _callNextHookEx = _user32! // // .lookup>('CallNextHookEx') // // .asFunction(); // // _getModuleHandle = _user32! // .lookup>('GetModuleHandleW') // .asFunction(); // // // _unhookHook = _user32! // // .lookup>('UnhookWindowsHookEx') // // .asFunction(); // } // // /// 윈도우키 차단 시작 // static void start() { // if (!Platform.isWindows) return; // // _loadLibraries(); // // final hModule = _getModuleHandle!.call(nullptr); // // final callback = Pointer.fromFunction(_keyboardHookCallback); // _callbackPtr = callback; // // _hookHandle = _setHook!.call(WH_KEYBOARD_LL, callback, hModule, 0); // // if (_hookHandle!.address == 0) { // print('❌ Failed to install keyboard hook!'); // } else { // print('✅ Windows Key Hook Installed'); // } // } // // /// 훅 제거 // static void stop() { // if (_hookHandle != null && _hookHandle!.address != 0) { // _unhookHook!.call(_hookHandle!.cast()); // _hookHandle = nullptr; // _callbackPtr = null; // print('🛑 Windows Key Hook Removed'); // } // } // }