Files
vnc_viewer/lib/utils/winkey_blocker.dart
2025-08-16 12:37:47 +09:00

166 lines
4.6 KiB
Dart

// // 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<Void>;
// typedef HMODULE = Pointer<Void>;
// typedef HWND = Pointer<Void>;
//
// // 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<Utf16> lpModuleName);
// typedef GetModuleHandleDart = Pointer Function(Pointer<Utf16> lpModuleName);
//
// // UnhookWindowsHookEx 타입
// typedef UnhookWindowsHookExFunc = Int32 Function(HHOOK hhk);
// typedef UnhookWindowsHookExDart = int Function(Pointer hhk);
// typedef KeyboardHookProc = Int32 Function(
// Int32 nCode,
// Int32 wParam,
// Pointer<KBDLLHOOKSTRUCT> lParam,
// );
//
// /// 윈도우키 차단기
// class WinKeyBlocker {
// static Pointer<HHOOK>? _hookHandle;
// static Pointer<NativeFunction<KeyboardHookProc>>? _callbackPtr;
//
// // 저수준 키보드 콜백 타입
//
// static int _keyboardHookCallback(
// int nCode,
// int wParam,
// Pointer<KBDLLHOOKSTRUCT> 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<NativeFunction<SetWindowsHookExFunc>>('SetWindowsHookExW')
// .asFunction<SetWindowsHookExDart>();
//
// // _callNextHookEx = _user32!
// // .lookup<NativeFunction<CallNextHookExFunc>>('CallNextHookEx')
// // .asFunction<CallNextHookExDart>();
//
// _getModuleHandle = _user32!
// .lookup<NativeFunction<GetModuleHandleFunc>>('GetModuleHandleW')
// .asFunction<GetModuleHandleDart>();
//
// // _unhookHook = _user32!
// // .lookup<NativeFunction<UnhookWindowsHookExFunc>>('UnhookWindowsHookEx')
// // .asFunction<UnhookWindowsHookExDart>();
// }
//
// /// 윈도우키 차단 시작
// static void start() {
// if (!Platform.isWindows) return;
//
// _loadLibraries();
//
// final hModule = _getModuleHandle!.call(nullptr);
//
// final callback = Pointer.fromFunction<KeyboardHookProc>(_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');
// }
// }
// }